<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"><html xmlns="http://www.w3.org/1999/xhtml"><head><link rel="stylesheet" type="text/css" href="style.css" /><script type="text/javascript" src="highlight.js"></script></head><body><pre><span class="hs-pragma">{-# LINE 1 &quot;libraries\\Win32\\System\\Win32\\Types.hsc&quot; #-}</span><span>
</span><span id="line-1"></span><span class="hs-pragma">{-# LANGUAGE CPP #-}</span><span>
</span><span id="line-2"></span><span class="hs-pragma">{-# LANGUAGE Trustworthy #-}</span><span>
</span><span id="line-3"></span><span class="hs-comment">-----------------------------------------------------------------------------</span><span>
</span><span id="line-4"></span><span class="hs-comment">-- |</span><span>
</span><span id="line-5"></span><span class="hs-comment">-- Module      :  System.Win32.Types</span><span>
</span><span id="line-6"></span><span class="hs-comment">-- Copyright   :  (c) Alastair Reid, 1997-2003</span><span>
</span><span id="line-7"></span><span class="hs-comment">-- License     :  BSD-style (see the file libraries/base/LICENSE)</span><span>
</span><span id="line-8"></span><span class="hs-comment">--</span><span>
</span><span id="line-9"></span><span class="hs-comment">-- Maintainer  :  Esa Ilari Vuokko &lt;ei@vuokko.info&gt;</span><span>
</span><span id="line-10"></span><span class="hs-comment">-- Stability   :  provisional</span><span>
</span><span id="line-11"></span><span class="hs-comment">-- Portability :  portable</span><span>
</span><span id="line-12"></span><span class="hs-comment">--</span><span>
</span><span id="line-13"></span><span class="hs-comment">-- A collection of FFI declarations for interfacing with Win32.</span><span>
</span><span id="line-14"></span><span class="hs-comment">--</span><span>
</span><span id="line-15"></span><span class="hs-comment">-----------------------------------------------------------------------------</span><span>
</span><span id="line-16"></span><span>
</span><span id="line-17"></span><span class="hs-keyword">module</span><span> </span><span class="hs-identifier">System.Win32.Types</span><span>
</span><span id="line-18"></span><span>        </span><span class="hs-special">(</span><span> </span><span class="hs-keyword">module</span><span> </span><span class="hs-identifier">System.Win32.Types</span><span>
</span><span id="line-19"></span><span>        </span><span class="hs-special">,</span><span> </span><span class="hs-identifier">nullPtr</span><span>
</span><span id="line-20"></span><span>        </span><span class="hs-special">)</span><span> </span><span class="hs-keyword">where</span><span>
</span><span id="line-21"></span><span>
</span><span id="line-22"></span><span class="hs-keyword">import</span><span> </span><span class="hs-identifier">Control.Concurrent.MVar</span><span> </span><span class="hs-special">(</span><span class="hs-identifier">readMVar</span><span class="hs-special">)</span><span>
</span><span id="line-23"></span><span class="hs-keyword">import</span><span> </span><span class="hs-identifier">Control.Exception</span><span> </span><span class="hs-special">(</span><span class="hs-identifier">bracket</span><span class="hs-special">,</span><span> </span><span class="hs-identifier">throwIO</span><span class="hs-special">)</span><span>
</span><span id="line-24"></span><span class="hs-keyword">import</span><span> </span><span class="hs-identifier">Data.Bits</span><span> </span><span class="hs-special">(</span><span class="hs-identifier">shiftL</span><span class="hs-special">,</span><span> </span><span class="hs-identifier">shiftR</span><span class="hs-special">,</span><span> </span><span class="hs-special">(</span><span class="hs-operator">.|.</span><span class="hs-special">)</span><span class="hs-special">,</span><span> </span><span class="hs-special">(</span><span class="hs-operator">.&amp;.</span><span class="hs-special">)</span><span class="hs-special">)</span><span>
</span><span id="line-25"></span><span class="hs-keyword">import</span><span> </span><span class="hs-identifier">Data.Char</span><span> </span><span class="hs-special">(</span><span class="hs-identifier">isSpace</span><span class="hs-special">)</span><span>
</span><span id="line-26"></span><span class="hs-keyword">import</span><span> </span><span class="hs-identifier">Data.Int</span><span> </span><span class="hs-special">(</span><span class="hs-identifier">Int32</span><span class="hs-special">,</span><span> </span><span class="hs-identifier">Int64</span><span class="hs-special">,</span><span> </span><span class="hs-identifier">Int16</span><span class="hs-special">)</span><span>
</span><span id="line-27"></span><span class="hs-keyword">import</span><span> </span><span class="hs-identifier">Data.Maybe</span><span> </span><span class="hs-special">(</span><span class="hs-identifier">fromMaybe</span><span class="hs-special">)</span><span>
</span><span id="line-28"></span><span class="hs-keyword">import</span><span> </span><span class="hs-identifier">Data.Typeable</span><span> </span><span class="hs-special">(</span><span class="hs-identifier">cast</span><span class="hs-special">)</span><span>
</span><span id="line-29"></span><span class="hs-keyword">import</span><span> </span><span class="hs-identifier">Data.Word</span><span> </span><span class="hs-special">(</span><span class="hs-identifier">Word8</span><span class="hs-special">,</span><span> </span><span class="hs-identifier">Word16</span><span class="hs-special">,</span><span> </span><span class="hs-identifier">Word32</span><span class="hs-special">,</span><span> </span><span class="hs-identifier">Word64</span><span class="hs-special">)</span><span>
</span><span id="line-30"></span><span class="hs-keyword">import</span><span> </span><span class="hs-identifier">Foreign.C.Error</span><span> </span><span class="hs-special">(</span><span class="hs-identifier">Errno</span><span class="hs-special">(</span><span class="hs-glyph">..</span><span class="hs-special">)</span><span class="hs-special">,</span><span> </span><span class="hs-identifier">errnoToIOError</span><span class="hs-special">)</span><span>
</span><span id="line-31"></span><span class="hs-keyword">import</span><span> </span><span class="hs-identifier">Foreign.C.String</span><span> </span><span class="hs-special">(</span><span class="hs-identifier">newCWString</span><span class="hs-special">,</span><span> </span><span class="hs-identifier">withCWStringLen</span><span class="hs-special">)</span><span>
</span><span id="line-32"></span><span class="hs-keyword">import</span><span> </span><span class="hs-identifier">Foreign.C.String</span><span> </span><span class="hs-special">(</span><span class="hs-identifier">peekCWString</span><span class="hs-special">,</span><span> </span><span class="hs-identifier">peekCWStringLen</span><span class="hs-special">,</span><span> </span><span class="hs-identifier">withCWString</span><span class="hs-special">)</span><span>
</span><span id="line-33"></span><span class="hs-keyword">import</span><span> </span><span class="hs-identifier">Foreign.C.Types</span><span> </span><span class="hs-special">(</span><span class="hs-identifier">CChar</span><span class="hs-special">,</span><span> </span><span class="hs-identifier">CUChar</span><span class="hs-special">,</span><span> </span><span class="hs-identifier">CWchar</span><span class="hs-special">,</span><span> </span><span class="hs-identifier">CInt</span><span class="hs-special">(</span><span class="hs-glyph">..</span><span class="hs-special">)</span><span class="hs-special">,</span><span> </span><span class="hs-identifier">CIntPtr</span><span class="hs-special">(</span><span class="hs-glyph">..</span><span class="hs-special">)</span><span class="hs-special">,</span><span> </span><span class="hs-identifier">CUIntPtr</span><span class="hs-special">)</span><span>
</span><span id="line-34"></span><span class="hs-keyword">import</span><span> </span><span class="hs-identifier">Foreign.ForeignPtr</span><span> </span><span class="hs-special">(</span><span class="hs-identifier">ForeignPtr</span><span class="hs-special">,</span><span> </span><span class="hs-identifier">newForeignPtr</span><span class="hs-special">,</span><span> </span><span class="hs-identifier">newForeignPtr_</span><span class="hs-special">)</span><span>
</span><span id="line-35"></span><span class="hs-keyword">import</span><span> </span><span class="hs-identifier">Foreign.Ptr</span><span> </span><span class="hs-special">(</span><span class="hs-identifier">FunPtr</span><span class="hs-special">,</span><span> </span><span class="hs-identifier">Ptr</span><span class="hs-special">,</span><span> </span><span class="hs-identifier">nullPtr</span><span class="hs-special">,</span><span> </span><span class="hs-identifier">ptrToIntPtr</span><span class="hs-special">)</span><span>
</span><span id="line-36"></span><span class="hs-keyword">import</span><span> </span><span class="hs-identifier">Foreign.StablePtr</span><span> </span><span class="hs-special">(</span><span class="hs-identifier">StablePtr</span><span class="hs-special">,</span><span> </span><span class="hs-identifier">freeStablePtr</span><span class="hs-special">,</span><span> </span><span class="hs-identifier">newStablePtr</span><span class="hs-special">)</span><span>
</span><span id="line-37"></span><span class="hs-keyword">import</span><span> </span><span class="hs-identifier">Foreign</span><span> </span><span class="hs-special">(</span><span class="hs-identifier">allocaArray</span><span class="hs-special">)</span><span>
</span><span id="line-38"></span><span class="hs-keyword">import</span><span> </span><span class="hs-identifier">GHC.IO.FD</span><span> </span><span class="hs-special">(</span><span class="hs-identifier">FD</span><span class="hs-special">(</span><span class="hs-glyph">..</span><span class="hs-special">)</span><span class="hs-special">)</span><span>
</span><span id="line-39"></span><span class="hs-keyword">import</span><span> </span><span class="hs-identifier">GHC.IO.Handle.FD</span><span> </span><span class="hs-special">(</span><span class="hs-identifier">fdToHandle</span><span class="hs-special">)</span><span>
</span><span id="line-40"></span><span class="hs-keyword">import</span><span> </span><span class="hs-identifier">GHC.IO.Handle.Types</span><span> </span><span class="hs-special">(</span><span class="hs-identifier">Handle</span><span class="hs-special">(</span><span class="hs-glyph">..</span><span class="hs-special">)</span><span class="hs-special">,</span><span> </span><span class="hs-identifier">Handle__</span><span class="hs-special">(</span><span class="hs-glyph">..</span><span class="hs-special">)</span><span class="hs-special">)</span><span>
</span><span id="line-41"></span><span class="hs-keyword">import</span><span> </span><span class="hs-identifier">Numeric</span><span> </span><span class="hs-special">(</span><span class="hs-identifier">showHex</span><span class="hs-special">)</span><span>
</span><span id="line-42"></span><span class="hs-keyword">import</span><span> </span><span class="hs-keyword">qualified</span><span> </span><span class="hs-identifier">System.IO</span><span> </span><span class="hs-keyword">as</span><span> </span><span class="hs-identifier">IO</span><span> </span><span class="hs-special">(</span><span class="hs-special">)</span><span>
</span><span id="line-43"></span><span class="hs-keyword">import</span><span> </span><span class="hs-identifier">System.IO.Error</span><span> </span><span class="hs-special">(</span><span class="hs-identifier">ioeSetErrorString</span><span class="hs-special">)</span><span>
</span><span id="line-44"></span><span class="hs-keyword">import</span><span> </span><span class="hs-identifier">System.IO.Unsafe</span><span> </span><span class="hs-special">(</span><span class="hs-identifier">unsafePerformIO</span><span class="hs-special">)</span><span>
</span><span id="line-45"></span><span>
</span><span id="line-46"></span><span>
</span><span id="line-47"></span><span class="hs-pragma">{-# LINE 49 &quot;libraries\\Win32\\System\\Win32\\Types.hsc&quot; #-}</span><span>
</span><span id="line-49"></span><span>
</span><span id="line-50"></span><span>
</span><span id="line-51"></span><span class="hs-pragma">{-# LINE 51 &quot;libraries\\Win32\\System\\Win32\\Types.hsc&quot; #-}</span><span>
</span><span id="line-51"></span><span class="hs-keyword">import</span><span> </span><span class="hs-identifier">Data.Bits</span><span> </span><span class="hs-special">(</span><span class="hs-identifier">finiteBitSize</span><span class="hs-special">)</span><span>
</span><span id="line-52"></span><span>
</span><span id="line-53"></span><span class="hs-pragma">{-# LINE 58 &quot;libraries\\Win32\\System\\Win32\\Types.hsc&quot; #-}</span><span class="hs-cpp">

#if defined(__IO_MANAGER_WINIO__)
</span><span class="hs-keyword">import</span><span> </span><span class="hs-identifier">GHC.IO.SubSystem</span><span> </span><span class="hs-special">(</span><span class="hs-special">(</span><span class="hs-operator">&lt;!&gt;</span><span class="hs-special">)</span><span class="hs-special">)</span><span>
</span><span id="line-61"></span><span class="hs-keyword">import</span><span> </span><span class="hs-identifier">GHC.IO.Handle.Windows</span><span>
</span><span id="line-62"></span><span class="hs-keyword">import</span><span> </span><span class="hs-identifier">GHC.IO.Windows.Handle</span><span> </span><span class="hs-special">(</span><span class="hs-identifier">fromHANDLE</span><span class="hs-special">,</span><span> </span><span class="hs-identifier">Io</span><span class="hs-special">(</span><span class="hs-special">)</span><span class="hs-special">,</span><span> </span><span class="hs-identifier">NativeHandle</span><span class="hs-special">(</span><span class="hs-special">)</span><span class="hs-special">,</span><span>
</span><span id="line-63"></span><span>                              </span><span class="hs-identifier">handleToMode</span><span class="hs-special">,</span><span> </span><span class="hs-identifier">optimizeFileAccess</span><span class="hs-special">)</span><span>
</span><span id="line-64"></span><span class="hs-keyword">import</span><span> </span><span class="hs-keyword">qualified</span><span> </span><span class="hs-identifier">GHC.Event.Windows</span><span> </span><span class="hs-keyword">as</span><span> </span><span class="hs-identifier">Mgr</span><span>
</span><span id="line-65"></span><span class="hs-keyword">import</span><span> </span><span class="hs-identifier">GHC.IO.Device</span><span> </span><span class="hs-special">(</span><span class="hs-identifier">IODeviceType</span><span class="hs-special">(</span><span class="hs-glyph">..</span><span class="hs-special">)</span><span class="hs-special">)</span><span class="hs-cpp">
#endif
</span><span class="hs-cpp">


#include &quot;windows_cconv.h&quot;
</span><span>
</span><span id="line-72"></span><span class="hs-comment">----------------------------------------------------------------</span><span>
</span><span id="line-73"></span><span class="hs-comment">-- Platform specific definitions</span><span>
</span><span id="line-74"></span><span class="hs-comment">--</span><span>
</span><span id="line-75"></span><span class="hs-comment">-- Most typedefs and prototypes in Win32 are expressed in terms</span><span>
</span><span id="line-76"></span><span class="hs-comment">-- of these types.  Try to follow suit - it'll make it easier to</span><span>
</span><span id="line-77"></span><span class="hs-comment">-- get things working on Win64 (or whatever they call it on Alphas).</span><span>
</span><span id="line-78"></span><span class="hs-comment">----------------------------------------------------------------</span><span>
</span><span id="line-79"></span><span>
</span><span id="line-80"></span><span class="hs-keyword">type</span><span> </span><span class="hs-identifier">BOOL</span><span>          </span><span class="hs-glyph">=</span><span> </span><span class="hs-identifier">Bool</span><span>
</span><span id="line-81"></span><span class="hs-keyword">type</span><span> </span><span class="hs-identifier">BYTE</span><span>          </span><span class="hs-glyph">=</span><span> </span><span class="hs-identifier">Word8</span><span>
</span><span id="line-82"></span><span class="hs-keyword">type</span><span> </span><span class="hs-identifier">UCHAR</span><span>         </span><span class="hs-glyph">=</span><span> </span><span class="hs-identifier">CUChar</span><span>
</span><span id="line-83"></span><span class="hs-keyword">type</span><span> </span><span class="hs-identifier">USHORT</span><span>        </span><span class="hs-glyph">=</span><span> </span><span class="hs-identifier">Word16</span><span>
</span><span id="line-84"></span><span class="hs-keyword">type</span><span> </span><span class="hs-identifier">UINT</span><span>          </span><span class="hs-glyph">=</span><span> </span><span class="hs-identifier">Word32</span><span>
</span><span id="line-85"></span><span class="hs-keyword">type</span><span> </span><span class="hs-identifier">INT</span><span>           </span><span class="hs-glyph">=</span><span> </span><span class="hs-identifier">Int32</span><span>
</span><span id="line-86"></span><span class="hs-keyword">type</span><span> </span><span class="hs-identifier">WORD</span><span>          </span><span class="hs-glyph">=</span><span> </span><span class="hs-identifier">Word16</span><span>
</span><span id="line-87"></span><span class="hs-keyword">type</span><span> </span><span class="hs-identifier">DWORD</span><span>         </span><span class="hs-glyph">=</span><span> </span><span class="hs-identifier">Word32</span><span>
</span><span id="line-88"></span><span class="hs-keyword">type</span><span> </span><span class="hs-identifier">LONG</span><span>          </span><span class="hs-glyph">=</span><span> </span><span class="hs-identifier">Int32</span><span>
</span><span id="line-89"></span><span class="hs-keyword">type</span><span> </span><span class="hs-identifier">FLOAT</span><span>         </span><span class="hs-glyph">=</span><span> </span><span class="hs-identifier">Float</span><span>
</span><span id="line-90"></span><span class="hs-keyword">type</span><span> </span><span class="hs-identifier">LARGE_INTEGER</span><span> </span><span class="hs-glyph">=</span><span> </span><span class="hs-identifier">Int64</span><span>
</span><span id="line-91"></span><span>
</span><span id="line-92"></span><span class="hs-keyword">type</span><span> </span><span class="hs-identifier">DWORD32</span><span>       </span><span class="hs-glyph">=</span><span> </span><span class="hs-identifier">Word32</span><span>
</span><span id="line-93"></span><span class="hs-keyword">type</span><span> </span><span class="hs-identifier">DWORD64</span><span>       </span><span class="hs-glyph">=</span><span> </span><span class="hs-identifier">Word64</span><span>
</span><span id="line-94"></span><span class="hs-keyword">type</span><span> </span><span class="hs-identifier">INT32</span><span>         </span><span class="hs-glyph">=</span><span> </span><span class="hs-identifier">Int32</span><span>
</span><span id="line-95"></span><span class="hs-keyword">type</span><span> </span><span class="hs-identifier">INT64</span><span>         </span><span class="hs-glyph">=</span><span> </span><span class="hs-identifier">Int64</span><span>
</span><span id="line-96"></span><span class="hs-keyword">type</span><span> </span><span class="hs-identifier">LONG32</span><span>        </span><span class="hs-glyph">=</span><span> </span><span class="hs-identifier">Int32</span><span>
</span><span id="line-97"></span><span class="hs-keyword">type</span><span> </span><span class="hs-identifier">LONG64</span><span>        </span><span class="hs-glyph">=</span><span> </span><span class="hs-identifier">Int64</span><span>
</span><span id="line-98"></span><span class="hs-keyword">type</span><span> </span><span class="hs-identifier">UINT32</span><span>        </span><span class="hs-glyph">=</span><span> </span><span class="hs-identifier">Word32</span><span>
</span><span id="line-99"></span><span class="hs-keyword">type</span><span> </span><span class="hs-identifier">UINT64</span><span>        </span><span class="hs-glyph">=</span><span> </span><span class="hs-identifier">Word64</span><span>
</span><span id="line-100"></span><span class="hs-keyword">type</span><span> </span><span class="hs-identifier">ULONG32</span><span>       </span><span class="hs-glyph">=</span><span> </span><span class="hs-identifier">Word32</span><span>
</span><span id="line-101"></span><span class="hs-keyword">type</span><span> </span><span class="hs-identifier">ULONG64</span><span>       </span><span class="hs-glyph">=</span><span> </span><span class="hs-identifier">Word64</span><span>
</span><span id="line-102"></span><span class="hs-keyword">type</span><span> </span><span class="hs-identifier">SHORT</span><span>         </span><span class="hs-glyph">=</span><span> </span><span class="hs-identifier">Int16</span><span>
</span><span id="line-103"></span><span>
</span><span id="line-104"></span><span class="hs-keyword">type</span><span> </span><span class="hs-identifier">INT_PTR</span><span>       </span><span class="hs-glyph">=</span><span> </span><span class="hs-identifier">Ptr</span><span> </span><span class="hs-identifier">CInt</span><span>
</span><span id="line-105"></span><span class="hs-keyword">type</span><span> </span><span class="hs-identifier">ULONG</span><span>         </span><span class="hs-glyph">=</span><span> </span><span class="hs-identifier">Word32</span><span>
</span><span id="line-106"></span><span class="hs-keyword">type</span><span> </span><span class="hs-identifier">UINT_PTR</span><span>      </span><span class="hs-glyph">=</span><span> </span><span class="hs-identifier">Word</span><span>
</span><span id="line-107"></span><span class="hs-keyword">type</span><span> </span><span class="hs-identifier">LONG_PTR</span><span>      </span><span class="hs-glyph">=</span><span> </span><span class="hs-identifier">CIntPtr</span><span>
</span><span id="line-108"></span><span class="hs-keyword">type</span><span> </span><span class="hs-identifier">ULONG_PTR</span><span>     </span><span class="hs-glyph">=</span><span> </span><span class="hs-identifier">CUIntPtr</span><span>
</span><span id="line-109"></span><span class="hs-keyword">type</span><span> </span><span class="hs-identifier">DWORD_PTR</span><span>     </span><span class="hs-glyph">=</span><span> </span><span class="hs-identifier">ULONG_PTR</span><span>
</span><span id="line-110"></span><span>
</span><span id="line-111"></span><span class="hs-pragma">{-# LINE 111 &quot;libraries\\Win32\\System\\Win32\\Types.hsc&quot; #-}</span><span>
</span><span id="line-111"></span><span class="hs-keyword">type</span><span> </span><span class="hs-identifier">HALF_PTR</span><span>      </span><span class="hs-glyph">=</span><span> </span><span class="hs-identifier">Ptr</span><span> </span><span class="hs-identifier">INT32</span><span>
</span><span id="line-112"></span><span>
</span><span id="line-113"></span><span class="hs-pragma">{-# LINE 115 &quot;libraries\\Win32\\System\\Win32\\Types.hsc&quot; #-}</span><span>
</span><span id="line-115"></span><span>
</span><span id="line-116"></span><span class="hs-comment">-- Not really a basic type, but used in many places</span><span>
</span><span id="line-117"></span><span class="hs-keyword">type</span><span> </span><span class="hs-identifier">DDWORD</span><span>        </span><span class="hs-glyph">=</span><span> </span><span class="hs-identifier">Word64</span><span>
</span><span id="line-118"></span><span>
</span><span id="line-119"></span><span class="hs-comment">----------------------------------------------------------------</span><span>
</span><span id="line-120"></span><span>
</span><span id="line-121"></span><span class="hs-keyword">type</span><span> </span><span class="hs-identifier">MbString</span><span>      </span><span class="hs-glyph">=</span><span> </span><span class="hs-identifier">Maybe</span><span> </span><span class="hs-identifier">String</span><span>
</span><span id="line-122"></span><span class="hs-keyword">type</span><span> </span><span class="hs-identifier">MbINT</span><span>         </span><span class="hs-glyph">=</span><span> </span><span class="hs-identifier">Maybe</span><span> </span><span class="hs-identifier">INT</span><span>
</span><span id="line-123"></span><span>
</span><span id="line-124"></span><span class="hs-keyword">type</span><span> </span><span class="hs-identifier">ATOM</span><span>          </span><span class="hs-glyph">=</span><span> </span><span class="hs-identifier">WORD</span><span>
</span><span id="line-125"></span><span class="hs-keyword">type</span><span> </span><span class="hs-identifier">WPARAM</span><span>        </span><span class="hs-glyph">=</span><span> </span><span class="hs-identifier">UINT_PTR</span><span>
</span><span id="line-126"></span><span class="hs-keyword">type</span><span> </span><span class="hs-identifier">LPARAM</span><span>        </span><span class="hs-glyph">=</span><span> </span><span class="hs-identifier">LONG_PTR</span><span>
</span><span id="line-127"></span><span class="hs-keyword">type</span><span> </span><span class="hs-identifier">LRESULT</span><span>       </span><span class="hs-glyph">=</span><span> </span><span class="hs-identifier">LONG_PTR</span><span>
</span><span id="line-128"></span><span class="hs-keyword">type</span><span> </span><span class="hs-identifier">SIZE_T</span><span>        </span><span class="hs-glyph">=</span><span> </span><span class="hs-identifier">ULONG_PTR</span><span>
</span><span id="line-129"></span><span>
</span><span id="line-130"></span><span class="hs-keyword">type</span><span> </span><span class="hs-identifier">MbATOM</span><span>        </span><span class="hs-glyph">=</span><span> </span><span class="hs-identifier">Maybe</span><span> </span><span class="hs-identifier">ATOM</span><span>
</span><span id="line-131"></span><span>
</span><span id="line-132"></span><span class="hs-keyword">type</span><span> </span><span class="hs-identifier">HRESULT</span><span>       </span><span class="hs-glyph">=</span><span> </span><span class="hs-identifier">LONG</span><span>
</span><span id="line-133"></span><span>
</span><span id="line-134"></span><span class="hs-comment">----------------------------------------------------------------</span><span>
</span><span id="line-135"></span><span class="hs-comment">-- Pointers</span><span>
</span><span id="line-136"></span><span class="hs-comment">----------------------------------------------------------------</span><span>
</span><span id="line-137"></span><span>
</span><span id="line-138"></span><span class="hs-keyword">type</span><span> </span><span class="hs-identifier">Addr</span><span>          </span><span class="hs-glyph">=</span><span> </span><span class="hs-identifier">Ptr</span><span> </span><span class="hs-special">(</span><span class="hs-special">)</span><span>
</span><span id="line-139"></span><span>
</span><span id="line-140"></span><span class="hs-keyword">type</span><span> </span><span class="hs-identifier">LPVOID</span><span>        </span><span class="hs-glyph">=</span><span> </span><span class="hs-identifier">Ptr</span><span> </span><span class="hs-special">(</span><span class="hs-special">)</span><span>
</span><span id="line-141"></span><span class="hs-keyword">type</span><span> </span><span class="hs-identifier">LPBOOL</span><span>        </span><span class="hs-glyph">=</span><span> </span><span class="hs-identifier">Ptr</span><span> </span><span class="hs-identifier">BOOL</span><span>
</span><span id="line-142"></span><span class="hs-keyword">type</span><span> </span><span class="hs-identifier">LPBYTE</span><span>        </span><span class="hs-glyph">=</span><span> </span><span class="hs-identifier">Ptr</span><span> </span><span class="hs-identifier">BYTE</span><span>
</span><span id="line-143"></span><span class="hs-keyword">type</span><span> </span><span class="hs-identifier">PUCHAR</span><span>        </span><span class="hs-glyph">=</span><span> </span><span class="hs-identifier">Ptr</span><span> </span><span class="hs-identifier">UCHAR</span><span>
</span><span id="line-144"></span><span class="hs-keyword">type</span><span> </span><span class="hs-identifier">LPDWORD</span><span>       </span><span class="hs-glyph">=</span><span> </span><span class="hs-identifier">Ptr</span><span> </span><span class="hs-identifier">DWORD</span><span>
</span><span id="line-145"></span><span class="hs-keyword">type</span><span> </span><span class="hs-identifier">LPSTR</span><span>         </span><span class="hs-glyph">=</span><span> </span><span class="hs-identifier">Ptr</span><span> </span><span class="hs-identifier">CChar</span><span>
</span><span id="line-146"></span><span class="hs-keyword">type</span><span> </span><span class="hs-identifier">LPCSTR</span><span>        </span><span class="hs-glyph">=</span><span> </span><span class="hs-identifier">LPSTR</span><span>
</span><span id="line-147"></span><span class="hs-keyword">type</span><span> </span><span class="hs-identifier">LPWSTR</span><span>        </span><span class="hs-glyph">=</span><span> </span><span class="hs-identifier">Ptr</span><span> </span><span class="hs-identifier">CWchar</span><span>
</span><span id="line-148"></span><span class="hs-keyword">type</span><span> </span><span class="hs-identifier">LPCWSTR</span><span>       </span><span class="hs-glyph">=</span><span> </span><span class="hs-identifier">LPWSTR</span><span>
</span><span id="line-149"></span><span class="hs-keyword">type</span><span> </span><span class="hs-identifier">LPTSTR</span><span>        </span><span class="hs-glyph">=</span><span> </span><span class="hs-identifier">Ptr</span><span> </span><span class="hs-identifier">TCHAR</span><span>
</span><span id="line-150"></span><span class="hs-keyword">type</span><span> </span><span class="hs-identifier">LPCTSTR</span><span>       </span><span class="hs-glyph">=</span><span> </span><span class="hs-identifier">LPTSTR</span><span>
</span><span id="line-151"></span><span class="hs-keyword">type</span><span> </span><span class="hs-identifier">LPCTSTR_</span><span>      </span><span class="hs-glyph">=</span><span> </span><span class="hs-identifier">LPCTSTR</span><span>
</span><span id="line-152"></span><span>
</span><span id="line-153"></span><span class="hs-comment">-- Optional things with defaults</span><span>
</span><span id="line-154"></span><span>
</span><span id="line-155"></span><span class="hs-identifier">maybePtr</span><span> </span><span class="hs-glyph">::</span><span> </span><span class="hs-identifier">Maybe</span><span> </span><span class="hs-special">(</span><span class="hs-identifier">Ptr</span><span> </span><span class="hs-identifier">a</span><span class="hs-special">)</span><span> </span><span class="hs-glyph">-&gt;</span><span> </span><span class="hs-identifier">Ptr</span><span> </span><span class="hs-identifier">a</span><span>
</span><span id="line-156"></span><span class="hs-identifier">maybePtr</span><span> </span><span class="hs-glyph">=</span><span> </span><span class="hs-identifier">fromMaybe</span><span> </span><span class="hs-identifier">nullPtr</span><span>
</span><span id="line-157"></span><span>
</span><span id="line-158"></span><span class="hs-identifier">ptrToMaybe</span><span> </span><span class="hs-glyph">::</span><span> </span><span class="hs-identifier">Ptr</span><span> </span><span class="hs-identifier">a</span><span> </span><span class="hs-glyph">-&gt;</span><span> </span><span class="hs-identifier">Maybe</span><span> </span><span class="hs-special">(</span><span class="hs-identifier">Ptr</span><span> </span><span class="hs-identifier">a</span><span class="hs-special">)</span><span>
</span><span id="line-159"></span><span class="hs-identifier">ptrToMaybe</span><span> </span><span class="hs-identifier">p</span><span> </span><span class="hs-glyph">=</span><span> </span><span class="hs-keyword">if</span><span> </span><span class="hs-identifier">p</span><span> </span><span class="hs-operator">==</span><span> </span><span class="hs-identifier">nullPtr</span><span> </span><span class="hs-keyword">then</span><span> </span><span class="hs-identifier">Nothing</span><span> </span><span class="hs-keyword">else</span><span> </span><span class="hs-identifier">Just</span><span> </span><span class="hs-identifier">p</span><span>
</span><span id="line-160"></span><span>
</span><span id="line-161"></span><span class="hs-identifier">maybeNum</span><span> </span><span class="hs-glyph">::</span><span> </span><span class="hs-identifier">Num</span><span> </span><span class="hs-identifier">a</span><span> </span><span class="hs-glyph">=&gt;</span><span> </span><span class="hs-identifier">Maybe</span><span> </span><span class="hs-identifier">a</span><span> </span><span class="hs-glyph">-&gt;</span><span> </span><span class="hs-identifier">a</span><span>
</span><span id="line-162"></span><span class="hs-identifier">maybeNum</span><span> </span><span class="hs-glyph">=</span><span> </span><span class="hs-identifier">fromMaybe</span><span> </span><span class="hs-number">0</span><span>
</span><span id="line-163"></span><span>
</span><span id="line-164"></span><span class="hs-identifier">numToMaybe</span><span> </span><span class="hs-glyph">::</span><span> </span><span class="hs-special">(</span><span class="hs-identifier">Eq</span><span> </span><span class="hs-identifier">a</span><span class="hs-special">,</span><span> </span><span class="hs-identifier">Num</span><span> </span><span class="hs-identifier">a</span><span class="hs-special">)</span><span> </span><span class="hs-glyph">=&gt;</span><span> </span><span class="hs-identifier">a</span><span> </span><span class="hs-glyph">-&gt;</span><span> </span><span class="hs-identifier">Maybe</span><span> </span><span class="hs-identifier">a</span><span>
</span><span id="line-165"></span><span class="hs-identifier">numToMaybe</span><span> </span><span class="hs-identifier">n</span><span> </span><span class="hs-glyph">=</span><span> </span><span class="hs-keyword">if</span><span> </span><span class="hs-identifier">n</span><span> </span><span class="hs-operator">==</span><span> </span><span class="hs-number">0</span><span> </span><span class="hs-keyword">then</span><span> </span><span class="hs-identifier">Nothing</span><span> </span><span class="hs-keyword">else</span><span> </span><span class="hs-identifier">Just</span><span> </span><span class="hs-identifier">n</span><span>
</span><span id="line-166"></span><span>
</span><span id="line-167"></span><span class="hs-keyword">type</span><span> </span><span class="hs-identifier">MbLPVOID</span><span>      </span><span class="hs-glyph">=</span><span> </span><span class="hs-identifier">Maybe</span><span> </span><span class="hs-identifier">LPVOID</span><span>
</span><span id="line-168"></span><span class="hs-keyword">type</span><span> </span><span class="hs-identifier">MbLPCSTR</span><span>      </span><span class="hs-glyph">=</span><span> </span><span class="hs-identifier">Maybe</span><span> </span><span class="hs-identifier">LPCSTR</span><span>
</span><span id="line-169"></span><span class="hs-keyword">type</span><span> </span><span class="hs-identifier">MbLPCTSTR</span><span>     </span><span class="hs-glyph">=</span><span> </span><span class="hs-identifier">Maybe</span><span> </span><span class="hs-identifier">LPCTSTR</span><span>
</span><span id="line-170"></span><span>
</span><span id="line-171"></span><span class="hs-comment">----------------------------------------------------------------</span><span>
</span><span id="line-172"></span><span class="hs-comment">-- Chars and strings</span><span>
</span><span id="line-173"></span><span class="hs-comment">----------------------------------------------------------------</span><span>
</span><span id="line-174"></span><span>
</span><span id="line-175"></span><span class="hs-identifier">withTString</span><span>    </span><span class="hs-glyph">::</span><span> </span><span class="hs-identifier">String</span><span> </span><span class="hs-glyph">-&gt;</span><span> </span><span class="hs-special">(</span><span class="hs-identifier">LPTSTR</span><span> </span><span class="hs-glyph">-&gt;</span><span> </span><span class="hs-identifier">IO</span><span> </span><span class="hs-identifier">a</span><span class="hs-special">)</span><span> </span><span class="hs-glyph">-&gt;</span><span> </span><span class="hs-identifier">IO</span><span> </span><span class="hs-identifier">a</span><span>
</span><span id="line-176"></span><span class="hs-identifier">withTStringLen</span><span> </span><span class="hs-glyph">::</span><span> </span><span class="hs-identifier">String</span><span> </span><span class="hs-glyph">-&gt;</span><span> </span><span class="hs-special">(</span><span class="hs-special">(</span><span class="hs-identifier">LPTSTR</span><span class="hs-special">,</span><span> </span><span class="hs-identifier">Int</span><span class="hs-special">)</span><span> </span><span class="hs-glyph">-&gt;</span><span> </span><span class="hs-identifier">IO</span><span> </span><span class="hs-identifier">a</span><span class="hs-special">)</span><span> </span><span class="hs-glyph">-&gt;</span><span> </span><span class="hs-identifier">IO</span><span> </span><span class="hs-identifier">a</span><span>
</span><span id="line-177"></span><span class="hs-identifier">peekTString</span><span>    </span><span class="hs-glyph">::</span><span> </span><span class="hs-identifier">LPCTSTR</span><span> </span><span class="hs-glyph">-&gt;</span><span> </span><span class="hs-identifier">IO</span><span> </span><span class="hs-identifier">String</span><span>
</span><span id="line-178"></span><span class="hs-identifier">peekTStringLen</span><span> </span><span class="hs-glyph">::</span><span> </span><span class="hs-special">(</span><span class="hs-identifier">LPCTSTR</span><span class="hs-special">,</span><span> </span><span class="hs-identifier">Int</span><span class="hs-special">)</span><span> </span><span class="hs-glyph">-&gt;</span><span> </span><span class="hs-identifier">IO</span><span> </span><span class="hs-identifier">String</span><span>
</span><span id="line-179"></span><span class="hs-identifier">newTString</span><span>     </span><span class="hs-glyph">::</span><span> </span><span class="hs-identifier">String</span><span> </span><span class="hs-glyph">-&gt;</span><span> </span><span class="hs-identifier">IO</span><span> </span><span class="hs-identifier">LPCTSTR</span><span>
</span><span id="line-180"></span><span>
</span><span id="line-181"></span><span class="hs-comment">-- UTF-16 version:</span><span>
</span><span id="line-182"></span><span class="hs-keyword">type</span><span> </span><span class="hs-identifier">TCHAR</span><span>     </span><span class="hs-glyph">=</span><span> </span><span class="hs-identifier">CWchar</span><span>
</span><span id="line-183"></span><span class="hs-identifier">withTString</span><span>    </span><span class="hs-glyph">=</span><span> </span><span class="hs-identifier">withCWString</span><span>
</span><span id="line-184"></span><span class="hs-identifier">withTStringLen</span><span> </span><span class="hs-glyph">=</span><span> </span><span class="hs-identifier">withCWStringLen</span><span>
</span><span id="line-185"></span><span class="hs-identifier">peekTString</span><span>    </span><span class="hs-glyph">=</span><span> </span><span class="hs-identifier">peekCWString</span><span>
</span><span id="line-186"></span><span class="hs-identifier">peekTStringLen</span><span> </span><span class="hs-glyph">=</span><span> </span><span class="hs-identifier">peekCWStringLen</span><span>
</span><span id="line-187"></span><span class="hs-identifier">newTString</span><span>     </span><span class="hs-glyph">=</span><span> </span><span class="hs-identifier">newCWString</span><span>
</span><span id="line-188"></span><span>
</span><span id="line-189"></span><span class="hs-comment">{- ANSI version:
type TCHAR     = CChar
withTString    = withCString
withTStringLen = withCStringLen
peekTString    = peekCString
peekTStringLen = peekCStringLen
newTString     = newCString
-}</span><span>
</span><span id="line-197"></span><span>
</span><span id="line-198"></span><span class="hs-comment">----------------------------------------------------------------</span><span>
</span><span id="line-199"></span><span class="hs-comment">-- Handles</span><span>
</span><span id="line-200"></span><span class="hs-comment">----------------------------------------------------------------</span><span>
</span><span id="line-201"></span><span>
</span><span id="line-202"></span><span class="hs-keyword">type</span><span>   </span><span class="hs-identifier">HANDLE</span><span>      </span><span class="hs-glyph">=</span><span> </span><span class="hs-identifier">Ptr</span><span> </span><span class="hs-special">(</span><span class="hs-special">)</span><span>
</span><span id="line-203"></span><span class="hs-keyword">type</span><span>   </span><span class="hs-identifier">ForeignHANDLE</span><span> </span><span class="hs-glyph">=</span><span> </span><span class="hs-identifier">ForeignPtr</span><span> </span><span class="hs-special">(</span><span class="hs-special">)</span><span>
</span><span id="line-204"></span><span>
</span><span id="line-205"></span><span class="hs-identifier">newForeignHANDLE</span><span> </span><span class="hs-glyph">::</span><span> </span><span class="hs-identifier">HANDLE</span><span> </span><span class="hs-glyph">-&gt;</span><span> </span><span class="hs-identifier">IO</span><span> </span><span class="hs-identifier">ForeignHANDLE</span><span>
</span><span id="line-206"></span><span class="hs-identifier">newForeignHANDLE</span><span> </span><span class="hs-glyph">=</span><span> </span><span class="hs-identifier">newForeignPtr</span><span> </span><span class="hs-identifier">deleteObjectFinaliser</span><span>
</span><span id="line-207"></span><span>
</span><span id="line-208"></span><span class="hs-identifier">handleToWord</span><span> </span><span class="hs-glyph">::</span><span> </span><span class="hs-identifier">HANDLE</span><span> </span><span class="hs-glyph">-&gt;</span><span> </span><span class="hs-identifier">UINT_PTR</span><span>
</span><span id="line-209"></span><span class="hs-identifier">handleToWord</span><span> </span><span class="hs-glyph">=</span><span> </span><span class="hs-identifier">castPtrToUINTPtr</span><span>
</span><span id="line-210"></span><span>
</span><span id="line-211"></span><span class="hs-keyword">type</span><span>   </span><span class="hs-identifier">HKEY</span><span>        </span><span class="hs-glyph">=</span><span> </span><span class="hs-identifier">ForeignHANDLE</span><span>
</span><span id="line-212"></span><span class="hs-keyword">type</span><span>   </span><span class="hs-identifier">PKEY</span><span>        </span><span class="hs-glyph">=</span><span> </span><span class="hs-identifier">HANDLE</span><span>
</span><span id="line-213"></span><span>
</span><span id="line-214"></span><span class="hs-identifier">nullHANDLE</span><span> </span><span class="hs-glyph">::</span><span> </span><span class="hs-identifier">HANDLE</span><span>
</span><span id="line-215"></span><span class="hs-identifier">nullHANDLE</span><span> </span><span class="hs-glyph">=</span><span> </span><span class="hs-identifier">nullPtr</span><span>
</span><span id="line-216"></span><span>
</span><span id="line-217"></span><span class="hs-keyword">type</span><span> </span><span class="hs-identifier">MbHANDLE</span><span>      </span><span class="hs-glyph">=</span><span> </span><span class="hs-identifier">Maybe</span><span> </span><span class="hs-identifier">HANDLE</span><span>
</span><span id="line-218"></span><span>
</span><span id="line-219"></span><span class="hs-identifier">nullHINSTANCE</span><span> </span><span class="hs-glyph">::</span><span> </span><span class="hs-identifier">HINSTANCE</span><span>
</span><span id="line-220"></span><span class="hs-identifier">nullHINSTANCE</span><span> </span><span class="hs-glyph">=</span><span> </span><span class="hs-identifier">nullPtr</span><span>
</span><span id="line-221"></span><span>
</span><span id="line-222"></span><span class="hs-keyword">type</span><span>   </span><span class="hs-identifier">HINSTANCE</span><span>   </span><span class="hs-glyph">=</span><span> </span><span class="hs-identifier">Ptr</span><span> </span><span class="hs-special">(</span><span class="hs-special">)</span><span>
</span><span id="line-223"></span><span class="hs-keyword">type</span><span> </span><span class="hs-identifier">MbHINSTANCE</span><span>   </span><span class="hs-glyph">=</span><span> </span><span class="hs-identifier">Maybe</span><span> </span><span class="hs-identifier">HINSTANCE</span><span>
</span><span id="line-224"></span><span>
</span><span id="line-225"></span><span class="hs-keyword">type</span><span>   </span><span class="hs-identifier">HMODULE</span><span>     </span><span class="hs-glyph">=</span><span> </span><span class="hs-identifier">Ptr</span><span> </span><span class="hs-special">(</span><span class="hs-special">)</span><span>
</span><span id="line-226"></span><span class="hs-keyword">type</span><span> </span><span class="hs-identifier">MbHMODULE</span><span>     </span><span class="hs-glyph">=</span><span> </span><span class="hs-identifier">Maybe</span><span> </span><span class="hs-identifier">HMODULE</span><span>
</span><span id="line-227"></span><span>
</span><span id="line-228"></span><span class="hs-identifier">nullFinalHANDLE</span><span> </span><span class="hs-glyph">::</span><span> </span><span class="hs-identifier">ForeignPtr</span><span> </span><span class="hs-identifier">a</span><span>
</span><span id="line-229"></span><span class="hs-identifier">nullFinalHANDLE</span><span> </span><span class="hs-glyph">=</span><span> </span><span class="hs-identifier">unsafePerformIO</span><span> </span><span class="hs-special">(</span><span class="hs-identifier">newForeignPtr_</span><span> </span><span class="hs-identifier">nullPtr</span><span class="hs-special">)</span><span>
</span><span id="line-230"></span><span>
</span><span id="line-231"></span><span class="hs-identifier">iNVALID_HANDLE_VALUE</span><span> </span><span class="hs-glyph">::</span><span> </span><span class="hs-identifier">HANDLE</span><span>
</span><span id="line-232"></span><span class="hs-identifier">iNVALID_HANDLE_VALUE</span><span> </span><span class="hs-glyph">=</span><span> </span><span class="hs-identifier">castUINTPtrToPtr</span><span> </span><span class="hs-identifier">maxBound</span><span>
</span><span id="line-233"></span><span>
</span><span id="line-234"></span><span class="hs-keyword">foreign</span><span> </span><span class="hs-keyword">import</span><span> </span><span class="hs-keyword">ccall</span><span> </span><span class="hs-string">&quot;_open_osfhandle&quot;</span><span>
</span><span id="line-235"></span><span>  </span><span class="hs-identifier">_open_osfhandle</span><span> </span><span class="hs-glyph">::</span><span> </span><span class="hs-identifier">CIntPtr</span><span> </span><span class="hs-glyph">-&gt;</span><span> </span><span class="hs-identifier">CInt</span><span> </span><span class="hs-glyph">-&gt;</span><span> </span><span class="hs-identifier">IO</span><span> </span><span class="hs-identifier">CInt</span><span>
</span><span id="line-236"></span><span>
</span><span id="line-237"></span><span class="hs-comment">-- | Create a Haskell 'Handle' from a Windows 'HANDLE'.</span><span>
</span><span id="line-238"></span><span class="hs-comment">--</span><span>
</span><span id="line-239"></span><span class="hs-comment">-- Beware that this function allocates a new file descriptor. A consequence of</span><span>
</span><span id="line-240"></span><span class="hs-comment">-- this is that calling 'hANDLEToHandle' on the standard Windows handles will</span><span>
</span><span id="line-241"></span><span class="hs-comment">-- not give you 'IO.stdin', 'IO.stdout', or 'IO.stderr'. For example, if you</span><span>
</span><span id="line-242"></span><span class="hs-comment">-- run this code:</span><span>
</span><span id="line-243"></span><span class="hs-comment">--</span><span>
</span><span id="line-244"></span><span class="hs-comment">-- @</span><span>
</span><span id="line-245"></span><span class="hs-comment">-- import Graphics.Win32.Misc</span><span>
</span><span id="line-246"></span><span class="hs-comment">-- stdoutHANDLE &lt;- getStdHandle sTD_OUTPUT_HANDLE</span><span>
</span><span id="line-247"></span><span class="hs-comment">-- stdout2 &lt;- 'hANDLEToHandle' stdoutHANDLE</span><span>
</span><span id="line-248"></span><span class="hs-comment">-- @</span><span>
</span><span id="line-249"></span><span class="hs-comment">--</span><span>
</span><span id="line-250"></span><span class="hs-comment">-- Then although you can use @stdout2@ to write to standard output, it is not</span><span>
</span><span id="line-251"></span><span class="hs-comment">-- the case that @'IO.stdout' == stdout2@.</span><span>
</span><span id="line-252"></span><span class="hs-identifier">hANDLEToHandle</span><span> </span><span class="hs-glyph">::</span><span> </span><span class="hs-identifier">HANDLE</span><span> </span><span class="hs-glyph">-&gt;</span><span> </span><span class="hs-identifier">IO</span><span> </span><span class="hs-identifier">Handle</span><span>
</span><span id="line-253"></span><span class="hs-identifier">hANDLEToHandle</span><span> </span><span class="hs-identifier">handle</span><span> </span><span class="hs-glyph">=</span><span> </span><span class="hs-identifier">posix</span><span class="hs-cpp">
#if defined(__IO_MANAGER_WINIO__)
</span><span>     </span><span class="hs-operator">&lt;!&gt;</span><span> </span><span class="hs-identifier">native</span><span class="hs-cpp">
#endif
</span><span>  </span><span class="hs-keyword">where</span><span class="hs-cpp">
#if defined(__IO_MANAGER_WINIO__)
</span><span>    </span><span class="hs-identifier">native</span><span> </span><span class="hs-glyph">=</span><span> </span><span class="hs-keyword">do</span><span>
</span><span id="line-260"></span><span>      </span><span class="hs-comment">-- Attach the handle to the I/O manager's CompletionPort.  This allows the</span><span>
</span><span id="line-261"></span><span>      </span><span class="hs-comment">-- I/O manager to service requests for this Handle.</span><span>
</span><span id="line-262"></span><span>      </span><span class="hs-identifier">Mgr.associateHandle'</span><span> </span><span class="hs-identifier">handle</span><span>
</span><span id="line-263"></span><span>      </span><span class="hs-identifier">optimizeFileAccess</span><span> </span><span class="hs-identifier">handle</span><span>
</span><span id="line-264"></span><span>      </span><span class="hs-keyword">let</span><span> </span><span class="hs-identifier">hwnd</span><span> </span><span class="hs-glyph">=</span><span> </span><span class="hs-identifier">fromHANDLE</span><span> </span><span class="hs-identifier">handle</span><span> </span><span class="hs-glyph">::</span><span> </span><span class="hs-identifier">Io</span><span> </span><span class="hs-identifier">NativeHandle</span><span>
</span><span id="line-265"></span><span>      </span><span class="hs-comment">-- Not sure if I need to use devType here..</span><span>
</span><span id="line-266"></span><span>      </span><span class="hs-identifier">mode</span><span> </span><span class="hs-glyph">&lt;-</span><span> </span><span class="hs-identifier">handleToMode</span><span> </span><span class="hs-identifier">handle</span><span>
</span><span id="line-267"></span><span>      </span><span class="hs-identifier">mkHandleFromHANDLE</span><span> </span><span class="hs-identifier">hwnd</span><span> </span><span class="hs-identifier">Stream</span><span> </span><span class="hs-special">(</span><span class="hs-string">&quot;hwnd:&quot;</span><span> </span><span class="hs-operator">++</span><span> </span><span class="hs-identifier">show</span><span> </span><span class="hs-identifier">handle</span><span class="hs-special">)</span><span> </span><span class="hs-identifier">mode</span><span> </span><span class="hs-identifier">Nothing</span><span class="hs-cpp">
#endif
</span><span>    </span><span class="hs-identifier">posix</span><span> </span><span class="hs-glyph">=</span><span> </span><span class="hs-identifier">_open_osfhandle</span><span> </span><span class="hs-special">(</span><span class="hs-identifier">fromIntegral</span><span> </span><span class="hs-special">(</span><span class="hs-identifier">ptrToIntPtr</span><span> </span><span class="hs-identifier">handle</span><span class="hs-special">)</span><span class="hs-special">)</span><span>
</span><span id="line-270"></span><span>                            </span><span class="hs-special">(</span><span class="hs-number">32768</span><span class="hs-special">)</span><span> </span><span class="hs-operator">&gt;&gt;=</span><span> </span><span class="hs-identifier">fdToHandle</span><span>
</span><span id="line-271"></span><span class="hs-pragma">{-# LINE 271 &quot;libraries\\Win32\\System\\Win32\\Types.hsc&quot; #-}</span><span>
</span><span id="line-271"></span><span>
</span><span id="line-272"></span><span class="hs-keyword">foreign</span><span> </span><span class="hs-keyword">import</span><span> </span><span class="hs-keyword">ccall</span><span> </span><span class="hs-keyword">unsafe</span><span> </span><span class="hs-string">&quot;_get_osfhandle&quot;</span><span>
</span><span id="line-273"></span><span>  </span><span class="hs-identifier">c_get_osfhandle</span><span> </span><span class="hs-glyph">::</span><span> </span><span class="hs-identifier">CInt</span><span> </span><span class="hs-glyph">-&gt;</span><span> </span><span class="hs-identifier">IO</span><span> </span><span class="hs-identifier">HANDLE</span><span>
</span><span id="line-274"></span><span>
</span><span id="line-275"></span><span class="hs-comment">-- | Extract a Windows 'HANDLE' from a Haskell 'Handle' and perform</span><span>
</span><span id="line-276"></span><span class="hs-comment">-- an action on it.</span><span>
</span><span id="line-277"></span><span>
</span><span id="line-278"></span><span class="hs-comment">-- Originally authored by Max Bolingbroke in the ansi-terminal library</span><span>
</span><span id="line-279"></span><span class="hs-identifier">withHandleToHANDLE</span><span> </span><span class="hs-glyph">::</span><span> </span><span class="hs-identifier">Handle</span><span> </span><span class="hs-glyph">-&gt;</span><span> </span><span class="hs-special">(</span><span class="hs-identifier">HANDLE</span><span> </span><span class="hs-glyph">-&gt;</span><span> </span><span class="hs-identifier">IO</span><span> </span><span class="hs-identifier">a</span><span class="hs-special">)</span><span> </span><span class="hs-glyph">-&gt;</span><span> </span><span class="hs-identifier">IO</span><span> </span><span class="hs-identifier">a</span><span class="hs-cpp">
#if defined(__IO_MANAGER_WINIO__)
</span><span class="hs-identifier">withHandleToHANDLE</span><span> </span><span class="hs-glyph">=</span><span> </span><span class="hs-identifier">withHandleToHANDLEPosix</span><span> </span><span class="hs-operator">&lt;!&gt;</span><span> </span><span class="hs-identifier">withHandleToHANDLENative</span><span class="hs-cpp">
#else
</span><span class="hs-identifier">withHandleToHANDLE</span><span> </span><span class="hs-glyph">=</span><span> </span><span class="hs-identifier">withHandleToHANDLEPosix</span><span class="hs-cpp">
#endif
</span><span class="hs-cpp">
#if defined(__IO_MANAGER_WINIO__)
</span><span class="hs-identifier">withHandleToHANDLENative</span><span> </span><span class="hs-glyph">::</span><span> </span><span class="hs-identifier">Handle</span><span> </span><span class="hs-glyph">-&gt;</span><span> </span><span class="hs-special">(</span><span class="hs-identifier">HANDLE</span><span> </span><span class="hs-glyph">-&gt;</span><span> </span><span class="hs-identifier">IO</span><span> </span><span class="hs-identifier">a</span><span class="hs-special">)</span><span> </span><span class="hs-glyph">-&gt;</span><span> </span><span class="hs-identifier">IO</span><span> </span><span class="hs-identifier">a</span><span>
</span><span id="line-288"></span><span class="hs-identifier">withHandleToHANDLENative</span><span> </span><span class="hs-identifier">haskell_handle</span><span> </span><span class="hs-identifier">action</span><span> </span><span class="hs-glyph">=</span><span>
</span><span id="line-289"></span><span>    </span><span class="hs-comment">-- Create a stable pointer to the Handle. This prevents the garbage collector</span><span>
</span><span id="line-290"></span><span>    </span><span class="hs-comment">-- getting to it while we are doing horrible manipulations with it, and hence</span><span>
</span><span id="line-291"></span><span>    </span><span class="hs-comment">-- stops it being finalized (and closed).</span><span>
</span><span id="line-292"></span><span>    </span><span class="hs-identifier">withStablePtr</span><span> </span><span class="hs-identifier">haskell_handle</span><span> </span><span class="hs-operator">$</span><span> </span><span class="hs-identifier">const</span><span> </span><span class="hs-operator">$</span><span> </span><span class="hs-keyword">do</span><span>
</span><span id="line-293"></span><span>        </span><span class="hs-identifier">windows_handle</span><span> </span><span class="hs-glyph">&lt;-</span><span> </span><span class="hs-identifier">handleToHANDLE</span><span> </span><span class="hs-identifier">haskell_handle</span><span>
</span><span id="line-294"></span><span>        </span><span class="hs-comment">-- Do what the user originally wanted</span><span>
</span><span id="line-295"></span><span>        </span><span class="hs-identifier">action</span><span> </span><span class="hs-identifier">windows_handle</span><span class="hs-cpp">
#endif
</span><span>
</span><span id="line-298"></span><span class="hs-identifier">withHandleToHANDLEPosix</span><span> </span><span class="hs-glyph">::</span><span> </span><span class="hs-identifier">Handle</span><span> </span><span class="hs-glyph">-&gt;</span><span> </span><span class="hs-special">(</span><span class="hs-identifier">HANDLE</span><span> </span><span class="hs-glyph">-&gt;</span><span> </span><span class="hs-identifier">IO</span><span> </span><span class="hs-identifier">a</span><span class="hs-special">)</span><span> </span><span class="hs-glyph">-&gt;</span><span> </span><span class="hs-identifier">IO</span><span> </span><span class="hs-identifier">a</span><span>
</span><span id="line-299"></span><span class="hs-identifier">withHandleToHANDLEPosix</span><span> </span><span class="hs-identifier">haskell_handle</span><span> </span><span class="hs-identifier">action</span><span> </span><span class="hs-glyph">=</span><span>
</span><span id="line-300"></span><span>    </span><span class="hs-comment">-- Create a stable pointer to the Handle. This prevents the garbage collector</span><span>
</span><span id="line-301"></span><span>    </span><span class="hs-comment">-- getting to it while we are doing horrible manipulations with it, and hence</span><span>
</span><span id="line-302"></span><span>    </span><span class="hs-comment">-- stops it being finalized (and closed).</span><span>
</span><span id="line-303"></span><span>    </span><span class="hs-identifier">withStablePtr</span><span> </span><span class="hs-identifier">haskell_handle</span><span> </span><span class="hs-operator">$</span><span> </span><span class="hs-identifier">const</span><span> </span><span class="hs-operator">$</span><span> </span><span class="hs-keyword">do</span><span>
</span><span id="line-304"></span><span>        </span><span class="hs-comment">-- Grab the write handle variable from the Handle</span><span>
</span><span id="line-305"></span><span>        </span><span class="hs-keyword">let</span><span> </span><span class="hs-identifier">write_handle_mvar</span><span> </span><span class="hs-glyph">=</span><span> </span><span class="hs-keyword">case</span><span> </span><span class="hs-identifier">haskell_handle</span><span> </span><span class="hs-keyword">of</span><span>
</span><span id="line-306"></span><span>                </span><span class="hs-identifier">FileHandle</span><span> </span><span class="hs-identifier">_</span><span> </span><span class="hs-identifier">handle_mvar</span><span>     </span><span class="hs-glyph">-&gt;</span><span> </span><span class="hs-identifier">handle_mvar</span><span>
</span><span id="line-307"></span><span>                </span><span class="hs-identifier">DuplexHandle</span><span> </span><span class="hs-identifier">_</span><span> </span><span class="hs-identifier">_</span><span> </span><span class="hs-identifier">handle_mvar</span><span> </span><span class="hs-glyph">-&gt;</span><span> </span><span class="hs-identifier">handle_mvar</span><span>
</span><span id="line-308"></span><span>                  </span><span class="hs-comment">-- This is &quot;write&quot; MVar, we could also take the &quot;read&quot; one</span><span>
</span><span id="line-309"></span><span>
</span><span id="line-310"></span><span>        </span><span class="hs-comment">-- Get the FD from the algebraic data type</span><span>
</span><span id="line-311"></span><span>        </span><span class="hs-identifier">Just</span><span> </span><span class="hs-identifier">fd</span><span> </span><span class="hs-glyph">&lt;-</span><span> </span><span class="hs-identifier">fmap</span><span> </span><span class="hs-special">(</span><span class="hs-glyph">\</span><span class="hs-special">(</span><span class="hs-identifier">Handle__</span><span> </span><span class="hs-special">{</span><span> </span><span class="hs-identifier">haDevice</span><span> </span><span class="hs-glyph">=</span><span> </span><span class="hs-identifier">dev</span><span> </span><span class="hs-special">}</span><span class="hs-special">)</span><span> </span><span class="hs-glyph">-&gt;</span><span> </span><span class="hs-identifier">fmap</span><span> </span><span class="hs-identifier">fdFD</span><span> </span><span class="hs-special">(</span><span class="hs-identifier">cast</span><span> </span><span class="hs-identifier">dev</span><span class="hs-special">)</span><span class="hs-special">)</span><span>
</span><span id="line-312"></span><span>                 </span><span class="hs-operator">$</span><span> </span><span class="hs-identifier">readMVar</span><span> </span><span class="hs-identifier">write_handle_mvar</span><span>
</span><span id="line-313"></span><span>
</span><span id="line-314"></span><span>        </span><span class="hs-comment">-- Finally, turn that (C-land) FD into a HANDLE using msvcrt</span><span>
</span><span id="line-315"></span><span>        </span><span class="hs-identifier">windows_handle</span><span> </span><span class="hs-glyph">&lt;-</span><span> </span><span class="hs-identifier">c_get_osfhandle</span><span> </span><span class="hs-identifier">fd</span><span>
</span><span id="line-316"></span><span>        </span><span class="hs-comment">-- Do what the user originally wanted</span><span>
</span><span id="line-317"></span><span>        </span><span class="hs-identifier">action</span><span> </span><span class="hs-identifier">windows_handle</span><span>
</span><span id="line-318"></span><span>
</span><span id="line-319"></span><span class="hs-identifier">withStablePtr</span><span> </span><span class="hs-glyph">::</span><span> </span><span class="hs-identifier">a</span><span> </span><span class="hs-glyph">-&gt;</span><span> </span><span class="hs-special">(</span><span class="hs-identifier">StablePtr</span><span> </span><span class="hs-identifier">a</span><span> </span><span class="hs-glyph">-&gt;</span><span> </span><span class="hs-identifier">IO</span><span> </span><span class="hs-identifier">b</span><span class="hs-special">)</span><span> </span><span class="hs-glyph">-&gt;</span><span> </span><span class="hs-identifier">IO</span><span> </span><span class="hs-identifier">b</span><span>
</span><span id="line-320"></span><span class="hs-identifier">withStablePtr</span><span> </span><span class="hs-identifier">value</span><span> </span><span class="hs-glyph">=</span><span> </span><span class="hs-identifier">bracket</span><span> </span><span class="hs-special">(</span><span class="hs-identifier">newStablePtr</span><span> </span><span class="hs-identifier">value</span><span class="hs-special">)</span><span> </span><span class="hs-identifier">freeStablePtr</span><span>
</span><span id="line-321"></span><span>
</span><span id="line-322"></span><span class="hs-comment">----------------------------------------------------------------</span><span>
</span><span id="line-323"></span><span class="hs-comment">-- Errors</span><span>
</span><span id="line-324"></span><span class="hs-comment">----------------------------------------------------------------</span><span>
</span><span id="line-325"></span><span>
</span><span id="line-326"></span><span class="hs-keyword">type</span><span> </span><span class="hs-identifier">ErrCode</span><span> </span><span class="hs-glyph">=</span><span> </span><span class="hs-identifier">DWORD</span><span>
</span><span id="line-327"></span><span>
</span><span id="line-328"></span><span class="hs-identifier">failIf</span><span> </span><span class="hs-glyph">::</span><span> </span><span class="hs-special">(</span><span class="hs-identifier">a</span><span> </span><span class="hs-glyph">-&gt;</span><span> </span><span class="hs-identifier">Bool</span><span class="hs-special">)</span><span> </span><span class="hs-glyph">-&gt;</span><span> </span><span class="hs-identifier">String</span><span> </span><span class="hs-glyph">-&gt;</span><span> </span><span class="hs-identifier">IO</span><span> </span><span class="hs-identifier">a</span><span> </span><span class="hs-glyph">-&gt;</span><span> </span><span class="hs-identifier">IO</span><span> </span><span class="hs-identifier">a</span><span>
</span><span id="line-329"></span><span class="hs-identifier">failIf</span><span> </span><span class="hs-identifier">p</span><span> </span><span class="hs-identifier">wh</span><span> </span><span class="hs-identifier">act</span><span> </span><span class="hs-glyph">=</span><span> </span><span class="hs-keyword">do</span><span>
</span><span id="line-330"></span><span>  </span><span class="hs-identifier">v</span><span> </span><span class="hs-glyph">&lt;-</span><span> </span><span class="hs-identifier">act</span><span>
</span><span id="line-331"></span><span>  </span><span class="hs-keyword">if</span><span> </span><span class="hs-identifier">p</span><span> </span><span class="hs-identifier">v</span><span> </span><span class="hs-keyword">then</span><span> </span><span class="hs-identifier">errorWin</span><span> </span><span class="hs-identifier">wh</span><span> </span><span class="hs-keyword">else</span><span> </span><span class="hs-identifier">return</span><span> </span><span class="hs-identifier">v</span><span>
</span><span id="line-332"></span><span>
</span><span id="line-333"></span><span class="hs-identifier">failIf_</span><span> </span><span class="hs-glyph">::</span><span> </span><span class="hs-special">(</span><span class="hs-identifier">a</span><span> </span><span class="hs-glyph">-&gt;</span><span> </span><span class="hs-identifier">Bool</span><span class="hs-special">)</span><span> </span><span class="hs-glyph">-&gt;</span><span> </span><span class="hs-identifier">String</span><span> </span><span class="hs-glyph">-&gt;</span><span> </span><span class="hs-identifier">IO</span><span> </span><span class="hs-identifier">a</span><span> </span><span class="hs-glyph">-&gt;</span><span> </span><span class="hs-identifier">IO</span><span> </span><span class="hs-special">(</span><span class="hs-special">)</span><span>
</span><span id="line-334"></span><span class="hs-identifier">failIf_</span><span> </span><span class="hs-identifier">p</span><span> </span><span class="hs-identifier">wh</span><span> </span><span class="hs-identifier">act</span><span> </span><span class="hs-glyph">=</span><span> </span><span class="hs-keyword">do</span><span>
</span><span id="line-335"></span><span>  </span><span class="hs-identifier">v</span><span> </span><span class="hs-glyph">&lt;-</span><span> </span><span class="hs-identifier">act</span><span>
</span><span id="line-336"></span><span>  </span><span class="hs-keyword">if</span><span> </span><span class="hs-identifier">p</span><span> </span><span class="hs-identifier">v</span><span> </span><span class="hs-keyword">then</span><span> </span><span class="hs-identifier">errorWin</span><span> </span><span class="hs-identifier">wh</span><span> </span><span class="hs-keyword">else</span><span> </span><span class="hs-identifier">return</span><span> </span><span class="hs-special">(</span><span class="hs-special">)</span><span>
</span><span id="line-337"></span><span>
</span><span id="line-338"></span><span class="hs-identifier">failIfNeg</span><span> </span><span class="hs-glyph">::</span><span> </span><span class="hs-special">(</span><span class="hs-identifier">Num</span><span> </span><span class="hs-identifier">a</span><span class="hs-special">,</span><span> </span><span class="hs-identifier">Ord</span><span> </span><span class="hs-identifier">a</span><span class="hs-special">)</span><span> </span><span class="hs-glyph">=&gt;</span><span> </span><span class="hs-identifier">String</span><span> </span><span class="hs-glyph">-&gt;</span><span> </span><span class="hs-identifier">IO</span><span> </span><span class="hs-identifier">a</span><span> </span><span class="hs-glyph">-&gt;</span><span> </span><span class="hs-identifier">IO</span><span> </span><span class="hs-identifier">a</span><span>
</span><span id="line-339"></span><span class="hs-identifier">failIfNeg</span><span> </span><span class="hs-glyph">=</span><span> </span><span class="hs-identifier">failIf</span><span> </span><span class="hs-special">(</span><span class="hs-operator">&lt;</span><span> </span><span class="hs-number">0</span><span class="hs-special">)</span><span>
</span><span id="line-340"></span><span>
</span><span id="line-341"></span><span class="hs-identifier">failIfNull</span><span> </span><span class="hs-glyph">::</span><span> </span><span class="hs-identifier">String</span><span> </span><span class="hs-glyph">-&gt;</span><span> </span><span class="hs-identifier">IO</span><span> </span><span class="hs-special">(</span><span class="hs-identifier">Ptr</span><span> </span><span class="hs-identifier">a</span><span class="hs-special">)</span><span> </span><span class="hs-glyph">-&gt;</span><span> </span><span class="hs-identifier">IO</span><span> </span><span class="hs-special">(</span><span class="hs-identifier">Ptr</span><span> </span><span class="hs-identifier">a</span><span class="hs-special">)</span><span>
</span><span id="line-342"></span><span class="hs-identifier">failIfNull</span><span> </span><span class="hs-glyph">=</span><span> </span><span class="hs-identifier">failIf</span><span> </span><span class="hs-special">(</span><span class="hs-operator">==</span><span> </span><span class="hs-identifier">nullPtr</span><span class="hs-special">)</span><span>
</span><span id="line-343"></span><span>
</span><span id="line-344"></span><span class="hs-identifier">failIfZero</span><span> </span><span class="hs-glyph">::</span><span> </span><span class="hs-special">(</span><span class="hs-identifier">Eq</span><span> </span><span class="hs-identifier">a</span><span class="hs-special">,</span><span> </span><span class="hs-identifier">Num</span><span> </span><span class="hs-identifier">a</span><span class="hs-special">)</span><span> </span><span class="hs-glyph">=&gt;</span><span> </span><span class="hs-identifier">String</span><span> </span><span class="hs-glyph">-&gt;</span><span> </span><span class="hs-identifier">IO</span><span> </span><span class="hs-identifier">a</span><span> </span><span class="hs-glyph">-&gt;</span><span> </span><span class="hs-identifier">IO</span><span> </span><span class="hs-identifier">a</span><span>
</span><span id="line-345"></span><span class="hs-identifier">failIfZero</span><span> </span><span class="hs-glyph">=</span><span> </span><span class="hs-identifier">failIf</span><span> </span><span class="hs-special">(</span><span class="hs-operator">==</span><span> </span><span class="hs-number">0</span><span class="hs-special">)</span><span>
</span><span id="line-346"></span><span>
</span><span id="line-347"></span><span class="hs-identifier">failIfFalse_</span><span> </span><span class="hs-glyph">::</span><span> </span><span class="hs-identifier">String</span><span> </span><span class="hs-glyph">-&gt;</span><span> </span><span class="hs-identifier">IO</span><span> </span><span class="hs-identifier">Bool</span><span> </span><span class="hs-glyph">-&gt;</span><span> </span><span class="hs-identifier">IO</span><span> </span><span class="hs-special">(</span><span class="hs-special">)</span><span>
</span><span id="line-348"></span><span class="hs-identifier">failIfFalse_</span><span> </span><span class="hs-glyph">=</span><span> </span><span class="hs-identifier">failIf_</span><span> </span><span class="hs-identifier">not</span><span>
</span><span id="line-349"></span><span>
</span><span id="line-350"></span><span class="hs-identifier">failUnlessSuccess</span><span> </span><span class="hs-glyph">::</span><span> </span><span class="hs-identifier">String</span><span> </span><span class="hs-glyph">-&gt;</span><span> </span><span class="hs-identifier">IO</span><span> </span><span class="hs-identifier">ErrCode</span><span> </span><span class="hs-glyph">-&gt;</span><span> </span><span class="hs-identifier">IO</span><span> </span><span class="hs-special">(</span><span class="hs-special">)</span><span>
</span><span id="line-351"></span><span class="hs-identifier">failUnlessSuccess</span><span> </span><span class="hs-identifier">fn_name</span><span> </span><span class="hs-identifier">act</span><span> </span><span class="hs-glyph">=</span><span> </span><span class="hs-keyword">do</span><span>
</span><span id="line-352"></span><span>  </span><span class="hs-identifier">r</span><span> </span><span class="hs-glyph">&lt;-</span><span> </span><span class="hs-identifier">act</span><span>
</span><span id="line-353"></span><span>  </span><span class="hs-keyword">if</span><span> </span><span class="hs-identifier">r</span><span> </span><span class="hs-operator">==</span><span> </span><span class="hs-number">0</span><span> </span><span class="hs-keyword">then</span><span> </span><span class="hs-identifier">return</span><span> </span><span class="hs-special">(</span><span class="hs-special">)</span><span> </span><span class="hs-keyword">else</span><span> </span><span class="hs-identifier">failWith</span><span> </span><span class="hs-identifier">fn_name</span><span> </span><span class="hs-identifier">r</span><span>
</span><span id="line-354"></span><span>
</span><span id="line-355"></span><span class="hs-identifier">failUnlessSuccessOr</span><span> </span><span class="hs-glyph">::</span><span> </span><span class="hs-identifier">ErrCode</span><span> </span><span class="hs-glyph">-&gt;</span><span> </span><span class="hs-identifier">String</span><span> </span><span class="hs-glyph">-&gt;</span><span> </span><span class="hs-identifier">IO</span><span> </span><span class="hs-identifier">ErrCode</span><span> </span><span class="hs-glyph">-&gt;</span><span> </span><span class="hs-identifier">IO</span><span> </span><span class="hs-identifier">Bool</span><span>
</span><span id="line-356"></span><span class="hs-identifier">failUnlessSuccessOr</span><span> </span><span class="hs-identifier">val</span><span> </span><span class="hs-identifier">fn_name</span><span> </span><span class="hs-identifier">act</span><span> </span><span class="hs-glyph">=</span><span> </span><span class="hs-keyword">do</span><span>
</span><span id="line-357"></span><span>  </span><span class="hs-identifier">r</span><span> </span><span class="hs-glyph">&lt;-</span><span> </span><span class="hs-identifier">act</span><span>
</span><span id="line-358"></span><span>  </span><span class="hs-keyword">if</span><span> </span><span class="hs-identifier">r</span><span> </span><span class="hs-operator">==</span><span> </span><span class="hs-number">0</span><span> </span><span class="hs-keyword">then</span><span> </span><span class="hs-identifier">return</span><span> </span><span class="hs-identifier">False</span><span>
</span><span id="line-359"></span><span>    </span><span class="hs-keyword">else</span><span> </span><span class="hs-keyword">if</span><span> </span><span class="hs-identifier">r</span><span> </span><span class="hs-operator">==</span><span> </span><span class="hs-identifier">val</span><span> </span><span class="hs-keyword">then</span><span> </span><span class="hs-identifier">return</span><span> </span><span class="hs-identifier">True</span><span>
</span><span id="line-360"></span><span>    </span><span class="hs-keyword">else</span><span> </span><span class="hs-identifier">failWith</span><span> </span><span class="hs-identifier">fn_name</span><span> </span><span class="hs-identifier">r</span><span>
</span><span id="line-361"></span><span>
</span><span id="line-362"></span><span class="hs-identifier">eRROR_INSUFFICIENT_BUFFER</span><span> </span><span class="hs-glyph">::</span><span> </span><span class="hs-identifier">ErrCode</span><span>
</span><span id="line-363"></span><span class="hs-identifier">eRROR_INSUFFICIENT_BUFFER</span><span> </span><span class="hs-glyph">=</span><span> </span><span class="hs-number">122</span><span>
</span><span id="line-364"></span><span class="hs-pragma">{-# LINE 364 &quot;libraries\\Win32\\System\\Win32\\Types.hsc&quot; #-}</span><span>
</span><span id="line-364"></span><span>
</span><span id="line-365"></span><span class="hs-identifier">eRROR_MOD_NOT_FOUND</span><span> </span><span class="hs-glyph">::</span><span> </span><span class="hs-identifier">ErrCode</span><span>
</span><span id="line-366"></span><span class="hs-identifier">eRROR_MOD_NOT_FOUND</span><span> </span><span class="hs-glyph">=</span><span> </span><span class="hs-number">126</span><span>
</span><span id="line-367"></span><span class="hs-pragma">{-# LINE 367 &quot;libraries\\Win32\\System\\Win32\\Types.hsc&quot; #-}</span><span>
</span><span id="line-367"></span><span>
</span><span id="line-368"></span><span class="hs-identifier">eRROR_PROC_NOT_FOUND</span><span> </span><span class="hs-glyph">::</span><span> </span><span class="hs-identifier">ErrCode</span><span>
</span><span id="line-369"></span><span class="hs-identifier">eRROR_PROC_NOT_FOUND</span><span> </span><span class="hs-glyph">=</span><span> </span><span class="hs-number">127</span><span>
</span><span id="line-370"></span><span class="hs-pragma">{-# LINE 370 &quot;libraries\\Win32\\System\\Win32\\Types.hsc&quot; #-}</span><span>
</span><span id="line-370"></span><span>
</span><span id="line-371"></span><span>
</span><span id="line-372"></span><span class="hs-identifier">errorWin</span><span> </span><span class="hs-glyph">::</span><span> </span><span class="hs-identifier">String</span><span> </span><span class="hs-glyph">-&gt;</span><span> </span><span class="hs-identifier">IO</span><span> </span><span class="hs-identifier">a</span><span>
</span><span id="line-373"></span><span class="hs-identifier">errorWin</span><span> </span><span class="hs-identifier">fn_name</span><span> </span><span class="hs-glyph">=</span><span> </span><span class="hs-keyword">do</span><span>
</span><span id="line-374"></span><span>  </span><span class="hs-identifier">err_code</span><span> </span><span class="hs-glyph">&lt;-</span><span> </span><span class="hs-identifier">getLastError</span><span>
</span><span id="line-375"></span><span>  </span><span class="hs-identifier">failWith</span><span> </span><span class="hs-identifier">fn_name</span><span> </span><span class="hs-identifier">err_code</span><span>
</span><span id="line-376"></span><span>
</span><span id="line-377"></span><span class="hs-identifier">failWith</span><span> </span><span class="hs-glyph">::</span><span> </span><span class="hs-identifier">String</span><span> </span><span class="hs-glyph">-&gt;</span><span> </span><span class="hs-identifier">ErrCode</span><span> </span><span class="hs-glyph">-&gt;</span><span> </span><span class="hs-identifier">IO</span><span> </span><span class="hs-identifier">a</span><span>
</span><span id="line-378"></span><span class="hs-identifier">failWith</span><span> </span><span class="hs-identifier">fn_name</span><span> </span><span class="hs-identifier">err_code</span><span> </span><span class="hs-glyph">=</span><span> </span><span class="hs-keyword">do</span><span>
</span><span id="line-379"></span><span>  </span><span class="hs-identifier">c_msg</span><span> </span><span class="hs-glyph">&lt;-</span><span> </span><span class="hs-identifier">getErrorMessage</span><span> </span><span class="hs-identifier">err_code</span><span>
</span><span id="line-380"></span><span>  </span><span class="hs-identifier">msg</span><span> </span><span class="hs-glyph">&lt;-</span><span> </span><span class="hs-keyword">if</span><span> </span><span class="hs-identifier">c_msg</span><span> </span><span class="hs-operator">==</span><span> </span><span class="hs-identifier">nullPtr</span><span>
</span><span id="line-381"></span><span>           </span><span class="hs-keyword">then</span><span> </span><span class="hs-identifier">return</span><span> </span><span class="hs-operator">$</span><span> </span><span class="hs-string">&quot;Error 0x&quot;</span><span> </span><span class="hs-operator">++</span><span> </span><span class="hs-identifier">Numeric.showHex</span><span> </span><span class="hs-identifier">err_code</span><span> </span><span class="hs-string">&quot;&quot;</span><span>
</span><span id="line-382"></span><span>           </span><span class="hs-keyword">else</span><span> </span><span class="hs-keyword">do</span><span> </span><span class="hs-identifier">msg</span><span> </span><span class="hs-glyph">&lt;-</span><span> </span><span class="hs-identifier">peekTString</span><span> </span><span class="hs-identifier">c_msg</span><span>
</span><span id="line-383"></span><span>                   </span><span class="hs-comment">-- We ignore failure of freeing c_msg, given we're already failing</span><span>
</span><span id="line-384"></span><span>                   </span><span class="hs-identifier">_</span><span> </span><span class="hs-glyph">&lt;-</span><span> </span><span class="hs-identifier">localFree</span><span> </span><span class="hs-identifier">c_msg</span><span>
</span><span id="line-385"></span><span>                   </span><span class="hs-identifier">return</span><span> </span><span class="hs-identifier">msg</span><span>
</span><span id="line-386"></span><span>  </span><span class="hs-comment">-- turn GetLastError() into errno, which errnoToIOError knows how to convert</span><span>
</span><span id="line-387"></span><span>  </span><span class="hs-comment">-- to an IOException we can throw.</span><span>
</span><span id="line-388"></span><span>  </span><span class="hs-identifier">errno</span><span> </span><span class="hs-glyph">&lt;-</span><span> </span><span class="hs-identifier">c_maperrno_func</span><span> </span><span class="hs-identifier">err_code</span><span>
</span><span id="line-389"></span><span>  </span><span class="hs-keyword">let</span><span> </span><span class="hs-identifier">msg'</span><span> </span><span class="hs-glyph">=</span><span> </span><span class="hs-identifier">reverse</span><span> </span><span class="hs-operator">$</span><span> </span><span class="hs-identifier">dropWhile</span><span> </span><span class="hs-identifier">isSpace</span><span> </span><span class="hs-operator">$</span><span> </span><span class="hs-identifier">reverse</span><span> </span><span class="hs-identifier">msg</span><span> </span><span class="hs-comment">-- drop trailing \n</span><span>
</span><span id="line-390"></span><span>      </span><span class="hs-identifier">ioerror</span><span> </span><span class="hs-glyph">=</span><span> </span><span class="hs-identifier">errnoToIOError</span><span> </span><span class="hs-identifier">fn_name</span><span> </span><span class="hs-identifier">errno</span><span> </span><span class="hs-identifier">Nothing</span><span> </span><span class="hs-identifier">Nothing</span><span>
</span><span id="line-391"></span><span>                  </span><span class="hs-special">`</span><span class="hs-identifier">ioeSetErrorString</span><span class="hs-special">`</span><span> </span><span class="hs-identifier">msg'</span><span>
</span><span id="line-392"></span><span>  </span><span class="hs-identifier">throwIO</span><span> </span><span class="hs-identifier">ioerror</span><span>
</span><span id="line-393"></span><span>
</span><span id="line-394"></span><span>
</span><span id="line-395"></span><span class="hs-keyword">foreign</span><span> </span><span class="hs-keyword">import</span><span> </span><span class="hs-keyword">ccall</span><span> </span><span class="hs-keyword">unsafe</span><span> </span><span class="hs-string">&quot;maperrno_func&quot;</span><span> </span><span class="hs-comment">-- in base/cbits/Win32Utils.c</span><span>
</span><span id="line-396"></span><span>   </span><span class="hs-identifier">c_maperrno_func</span><span> </span><span class="hs-glyph">::</span><span> </span><span class="hs-identifier">ErrCode</span><span> </span><span class="hs-glyph">-&gt;</span><span> </span><span class="hs-identifier">IO</span><span> </span><span class="hs-identifier">Errno</span><span>
</span><span id="line-397"></span><span>
</span><span id="line-398"></span><span class="hs-comment">----------------------------------------------------------------</span><span>
</span><span id="line-399"></span><span class="hs-comment">-- Misc helpers</span><span>
</span><span id="line-400"></span><span class="hs-comment">----------------------------------------------------------------</span><span>
</span><span id="line-401"></span><span>
</span><span id="line-402"></span><span class="hs-identifier">ddwordToDwords</span><span> </span><span class="hs-glyph">::</span><span> </span><span class="hs-identifier">DDWORD</span><span> </span><span class="hs-glyph">-&gt;</span><span> </span><span class="hs-special">(</span><span class="hs-identifier">DWORD</span><span class="hs-special">,</span><span class="hs-identifier">DWORD</span><span class="hs-special">)</span><span>
</span><span id="line-403"></span><span class="hs-identifier">ddwordToDwords</span><span> </span><span class="hs-identifier">n</span><span> </span><span class="hs-glyph">=</span><span>
</span><span id="line-404"></span><span>        </span><span class="hs-special">(</span><span class="hs-identifier">fromIntegral</span><span> </span><span class="hs-special">(</span><span class="hs-identifier">n</span><span> </span><span class="hs-special">`</span><span class="hs-identifier">shiftR</span><span class="hs-special">`</span><span> </span><span class="hs-identifier">finiteBitSize</span><span> </span><span class="hs-special">(</span><span class="hs-identifier">undefined</span><span> </span><span class="hs-glyph">::</span><span> </span><span class="hs-identifier">DWORD</span><span class="hs-special">)</span><span class="hs-special">)</span><span>
</span><span id="line-405"></span><span>        </span><span class="hs-special">,</span><span class="hs-identifier">fromIntegral</span><span> </span><span class="hs-special">(</span><span class="hs-identifier">n</span><span> </span><span class="hs-operator">.&amp;.</span><span> </span><span class="hs-identifier">fromIntegral</span><span> </span><span class="hs-special">(</span><span class="hs-identifier">maxBound</span><span> </span><span class="hs-glyph">::</span><span> </span><span class="hs-identifier">DWORD</span><span class="hs-special">)</span><span class="hs-special">)</span><span class="hs-special">)</span><span>
</span><span id="line-406"></span><span>
</span><span id="line-407"></span><span class="hs-identifier">dwordsToDdword</span><span class="hs-glyph">::</span><span> </span><span class="hs-special">(</span><span class="hs-identifier">DWORD</span><span class="hs-special">,</span><span class="hs-identifier">DWORD</span><span class="hs-special">)</span><span> </span><span class="hs-glyph">-&gt;</span><span> </span><span class="hs-identifier">DDWORD</span><span>
</span><span id="line-408"></span><span class="hs-identifier">dwordsToDdword</span><span> </span><span class="hs-special">(</span><span class="hs-identifier">hi</span><span class="hs-special">,</span><span class="hs-identifier">low</span><span class="hs-special">)</span><span> </span><span class="hs-glyph">=</span><span> </span><span class="hs-special">(</span><span class="hs-identifier">fromIntegral</span><span> </span><span class="hs-identifier">low</span><span class="hs-special">)</span><span> </span><span class="hs-operator">.|.</span><span> </span><span class="hs-special">(</span><span class="hs-identifier">fromIntegral</span><span> </span><span class="hs-identifier">hi</span><span> </span><span class="hs-special">`</span><span class="hs-identifier">shiftL</span><span class="hs-special">`</span><span> </span><span class="hs-identifier">finiteBitSize</span><span> </span><span class="hs-identifier">hi</span><span class="hs-special">)</span><span>
</span><span id="line-409"></span><span>
</span><span id="line-410"></span><span class="hs-comment">-- Support for API calls that are passed a fixed-size buffer and tell</span><span>
</span><span id="line-411"></span><span class="hs-comment">-- you via the return value if the buffer was too small.  In that</span><span>
</span><span id="line-412"></span><span class="hs-comment">-- case, we double the buffer size and try again.</span><span>
</span><span id="line-413"></span><span class="hs-identifier">try</span><span> </span><span class="hs-glyph">::</span><span> </span><span class="hs-identifier">String</span><span> </span><span class="hs-glyph">-&gt;</span><span> </span><span class="hs-special">(</span><span class="hs-identifier">LPTSTR</span><span> </span><span class="hs-glyph">-&gt;</span><span> </span><span class="hs-identifier">UINT</span><span> </span><span class="hs-glyph">-&gt;</span><span> </span><span class="hs-identifier">IO</span><span> </span><span class="hs-identifier">UINT</span><span class="hs-special">)</span><span> </span><span class="hs-glyph">-&gt;</span><span> </span><span class="hs-identifier">UINT</span><span> </span><span class="hs-glyph">-&gt;</span><span> </span><span class="hs-identifier">IO</span><span> </span><span class="hs-identifier">String</span><span>
</span><span id="line-414"></span><span class="hs-identifier">try</span><span> </span><span class="hs-identifier">loc</span><span> </span><span class="hs-identifier">f</span><span> </span><span class="hs-identifier">n</span><span> </span><span class="hs-glyph">=</span><span> </span><span class="hs-keyword">do</span><span>
</span><span id="line-415"></span><span>   </span><span class="hs-identifier">e</span><span> </span><span class="hs-glyph">&lt;-</span><span> </span><span class="hs-identifier">allocaArray</span><span> </span><span class="hs-special">(</span><span class="hs-identifier">fromIntegral</span><span> </span><span class="hs-identifier">n</span><span class="hs-special">)</span><span> </span><span class="hs-operator">$</span><span> </span><span class="hs-glyph">\</span><span class="hs-identifier">lptstr</span><span> </span><span class="hs-glyph">-&gt;</span><span> </span><span class="hs-keyword">do</span><span>
</span><span id="line-416"></span><span>          </span><span class="hs-identifier">r</span><span> </span><span class="hs-glyph">&lt;-</span><span> </span><span class="hs-identifier">failIfZero</span><span> </span><span class="hs-identifier">loc</span><span> </span><span class="hs-operator">$</span><span> </span><span class="hs-identifier">f</span><span> </span><span class="hs-identifier">lptstr</span><span> </span><span class="hs-identifier">n</span><span>
</span><span id="line-417"></span><span>          </span><span class="hs-keyword">if</span><span> </span><span class="hs-special">(</span><span class="hs-identifier">r</span><span> </span><span class="hs-operator">&gt;</span><span> </span><span class="hs-identifier">n</span><span class="hs-special">)</span><span> </span><span class="hs-keyword">then</span><span> </span><span class="hs-identifier">return</span><span> </span><span class="hs-special">(</span><span class="hs-identifier">Left</span><span> </span><span class="hs-identifier">r</span><span class="hs-special">)</span><span> </span><span class="hs-keyword">else</span><span> </span><span class="hs-keyword">do</span><span>
</span><span id="line-418"></span><span>            </span><span class="hs-identifier">str</span><span> </span><span class="hs-glyph">&lt;-</span><span> </span><span class="hs-identifier">peekTStringLen</span><span> </span><span class="hs-special">(</span><span class="hs-identifier">lptstr</span><span class="hs-special">,</span><span> </span><span class="hs-identifier">fromIntegral</span><span> </span><span class="hs-identifier">r</span><span class="hs-special">)</span><span>
</span><span id="line-419"></span><span>            </span><span class="hs-identifier">return</span><span> </span><span class="hs-special">(</span><span class="hs-identifier">Right</span><span> </span><span class="hs-identifier">str</span><span class="hs-special">)</span><span>
</span><span id="line-420"></span><span>   </span><span class="hs-keyword">case</span><span> </span><span class="hs-identifier">e</span><span> </span><span class="hs-keyword">of</span><span>
</span><span id="line-421"></span><span>        </span><span class="hs-identifier">Left</span><span> </span><span class="hs-identifier">n'</span><span>   </span><span class="hs-glyph">-&gt;</span><span> </span><span class="hs-identifier">try</span><span> </span><span class="hs-identifier">loc</span><span> </span><span class="hs-identifier">f</span><span> </span><span class="hs-identifier">n'</span><span>
</span><span id="line-422"></span><span>        </span><span class="hs-identifier">Right</span><span> </span><span class="hs-identifier">str</span><span> </span><span class="hs-glyph">-&gt;</span><span> </span><span class="hs-identifier">return</span><span> </span><span class="hs-identifier">str</span><span>
</span><span id="line-423"></span><span>
</span><span id="line-424"></span><span class="hs-comment">----------------------------------------------------------------</span><span>
</span><span id="line-425"></span><span class="hs-comment">-- Primitives</span><span>
</span><span id="line-426"></span><span class="hs-comment">----------------------------------------------------------------</span><span>
</span><span id="line-427"></span><span>
</span><span id="line-428"></span><span class="hs-pragma">{-# CFILES cbits/HsWin32.c #-}</span><span>
</span><span id="line-429"></span><span class="hs-keyword">foreign</span><span> </span><span class="hs-keyword">import</span><span> </span><span class="hs-keyword">ccall</span><span> </span><span class="hs-string">&quot;HsWin32.h &amp;DeleteObjectFinaliser&quot;</span><span>
</span><span id="line-430"></span><span>  </span><span class="hs-identifier">deleteObjectFinaliser</span><span> </span><span class="hs-glyph">::</span><span> </span><span class="hs-identifier">FunPtr</span><span> </span><span class="hs-special">(</span><span class="hs-identifier">Ptr</span><span> </span><span class="hs-identifier">a</span><span> </span><span class="hs-glyph">-&gt;</span><span> </span><span class="hs-identifier">IO</span><span> </span><span class="hs-special">(</span><span class="hs-special">)</span><span class="hs-special">)</span><span>
</span><span id="line-431"></span><span>
</span><span id="line-432"></span><span class="hs-keyword">foreign</span><span> </span><span class="hs-keyword">import</span><span> </span><span class="hs-identifier">WINDOWS_CCONV</span><span> </span><span class="hs-keyword">unsafe</span><span> </span><span class="hs-string">&quot;windows.h LocalFree&quot;</span><span>
</span><span id="line-433"></span><span>  </span><span class="hs-identifier">localFree</span><span> </span><span class="hs-glyph">::</span><span> </span><span class="hs-identifier">Ptr</span><span> </span><span class="hs-identifier">a</span><span> </span><span class="hs-glyph">-&gt;</span><span> </span><span class="hs-identifier">IO</span><span> </span><span class="hs-special">(</span><span class="hs-identifier">Ptr</span><span> </span><span class="hs-identifier">a</span><span class="hs-special">)</span><span>
</span><span id="line-434"></span><span>
</span><span id="line-435"></span><span class="hs-keyword">foreign</span><span> </span><span class="hs-keyword">import</span><span> </span><span class="hs-identifier">WINDOWS_CCONV</span><span> </span><span class="hs-keyword">unsafe</span><span> </span><span class="hs-string">&quot;windows.h GetLastError&quot;</span><span>
</span><span id="line-436"></span><span>  </span><span class="hs-identifier">getLastError</span><span> </span><span class="hs-glyph">::</span><span> </span><span class="hs-identifier">IO</span><span> </span><span class="hs-identifier">ErrCode</span><span>
</span><span id="line-437"></span><span>
</span><span id="line-438"></span><span class="hs-keyword">foreign</span><span> </span><span class="hs-keyword">import</span><span> </span><span class="hs-identifier">WINDOWS_CCONV</span><span> </span><span class="hs-keyword">unsafe</span><span> </span><span class="hs-string">&quot;windows.h SetLastError&quot;</span><span>
</span><span id="line-439"></span><span>  </span><span class="hs-identifier">setLastError</span><span> </span><span class="hs-glyph">::</span><span> </span><span class="hs-identifier">ErrCode</span><span> </span><span class="hs-glyph">-&gt;</span><span> </span><span class="hs-identifier">IO</span><span> </span><span class="hs-special">(</span><span class="hs-special">)</span><span>
</span><span id="line-440"></span><span>
</span><span id="line-441"></span><span class="hs-pragma">{-# CFILES cbits/errors.c #-}</span><span>
</span><span id="line-442"></span><span>
</span><span id="line-443"></span><span class="hs-keyword">foreign</span><span> </span><span class="hs-keyword">import</span><span> </span><span class="hs-keyword">ccall</span><span> </span><span class="hs-keyword">unsafe</span><span> </span><span class="hs-string">&quot;errors.h&quot;</span><span>
</span><span id="line-444"></span><span>  </span><span class="hs-identifier">getErrorMessage</span><span> </span><span class="hs-glyph">::</span><span> </span><span class="hs-identifier">DWORD</span><span> </span><span class="hs-glyph">-&gt;</span><span> </span><span class="hs-identifier">IO</span><span> </span><span class="hs-identifier">LPWSTR</span><span>
</span><span id="line-445"></span><span>
</span><span id="line-446"></span><span class="hs-pragma">{-# CFILES cbits/HsWin32.c #-}</span><span>
</span><span id="line-447"></span><span>
</span><span id="line-448"></span><span class="hs-keyword">foreign</span><span> </span><span class="hs-keyword">import</span><span> </span><span class="hs-keyword">ccall</span><span> </span><span class="hs-keyword">unsafe</span><span> </span><span class="hs-string">&quot;HsWin32.h&quot;</span><span>
</span><span id="line-449"></span><span>  </span><span class="hs-identifier">lOWORD</span><span> </span><span class="hs-glyph">::</span><span> </span><span class="hs-identifier">DWORD</span><span> </span><span class="hs-glyph">-&gt;</span><span> </span><span class="hs-identifier">WORD</span><span>
</span><span id="line-450"></span><span>
</span><span id="line-451"></span><span class="hs-keyword">foreign</span><span> </span><span class="hs-keyword">import</span><span> </span><span class="hs-keyword">ccall</span><span> </span><span class="hs-keyword">unsafe</span><span> </span><span class="hs-string">&quot;HsWin32.h&quot;</span><span>
</span><span id="line-452"></span><span>  </span><span class="hs-identifier">hIWORD</span><span> </span><span class="hs-glyph">::</span><span> </span><span class="hs-identifier">DWORD</span><span> </span><span class="hs-glyph">-&gt;</span><span> </span><span class="hs-identifier">WORD</span><span>
</span><span id="line-453"></span><span>
</span><span id="line-454"></span><span class="hs-keyword">foreign</span><span> </span><span class="hs-keyword">import</span><span> </span><span class="hs-keyword">ccall</span><span> </span><span class="hs-keyword">unsafe</span><span> </span><span class="hs-string">&quot;HsWin32.h&quot;</span><span>
</span><span id="line-455"></span><span>  </span><span class="hs-identifier">castUINTPtrToPtr</span><span> </span><span class="hs-glyph">::</span><span> </span><span class="hs-identifier">UINT_PTR</span><span> </span><span class="hs-glyph">-&gt;</span><span> </span><span class="hs-identifier">Ptr</span><span> </span><span class="hs-identifier">a</span><span>
</span><span id="line-456"></span><span>
</span><span id="line-457"></span><span class="hs-keyword">foreign</span><span> </span><span class="hs-keyword">import</span><span> </span><span class="hs-keyword">ccall</span><span> </span><span class="hs-keyword">unsafe</span><span> </span><span class="hs-string">&quot;HsWin32.h&quot;</span><span>
</span><span id="line-458"></span><span>  </span><span class="hs-identifier">castPtrToUINTPtr</span><span> </span><span class="hs-glyph">::</span><span> </span><span class="hs-identifier">Ptr</span><span> </span><span class="hs-identifier">s</span><span> </span><span class="hs-glyph">-&gt;</span><span> </span><span class="hs-identifier">UINT_PTR</span><span>
</span><span id="line-459"></span><span>
</span><span id="line-460"></span><span class="hs-keyword">type</span><span> </span><span class="hs-identifier">LCID</span><span> </span><span class="hs-glyph">=</span><span> </span><span class="hs-identifier">DWORD</span><span>
</span><span id="line-461"></span><span>
</span><span id="line-462"></span><span class="hs-keyword">type</span><span> </span><span class="hs-identifier">LANGID</span><span> </span><span class="hs-glyph">=</span><span> </span><span class="hs-identifier">WORD</span><span>
</span><span id="line-463"></span><span class="hs-keyword">type</span><span> </span><span class="hs-identifier">SortID</span><span> </span><span class="hs-glyph">=</span><span> </span><span class="hs-identifier">WORD</span><span>
</span><span id="line-464"></span><span>
</span><span id="line-465"></span><span class="hs-keyword">foreign</span><span> </span><span class="hs-keyword">import</span><span> </span><span class="hs-keyword">ccall</span><span> </span><span class="hs-keyword">unsafe</span><span> </span><span class="hs-string">&quot;HsWin32.h prim_MAKELCID&quot;</span><span>
</span><span id="line-466"></span><span>  </span><span class="hs-identifier">mAKELCID</span><span> </span><span class="hs-glyph">::</span><span> </span><span class="hs-identifier">LANGID</span><span> </span><span class="hs-glyph">-&gt;</span><span> </span><span class="hs-identifier">SortID</span><span> </span><span class="hs-glyph">-&gt;</span><span> </span><span class="hs-identifier">LCID</span><span>
</span><span id="line-467"></span><span>
</span><span id="line-468"></span><span class="hs-keyword">foreign</span><span> </span><span class="hs-keyword">import</span><span> </span><span class="hs-keyword">ccall</span><span> </span><span class="hs-keyword">unsafe</span><span> </span><span class="hs-string">&quot;HsWin32.h prim_LANGIDFROMLCID&quot;</span><span>
</span><span id="line-469"></span><span>  </span><span class="hs-identifier">lANGIDFROMLCID</span><span> </span><span class="hs-glyph">::</span><span> </span><span class="hs-identifier">LCID</span><span> </span><span class="hs-glyph">-&gt;</span><span> </span><span class="hs-identifier">LANGID</span><span>
</span><span id="line-470"></span><span>
</span><span id="line-471"></span><span class="hs-keyword">foreign</span><span> </span><span class="hs-keyword">import</span><span> </span><span class="hs-keyword">ccall</span><span> </span><span class="hs-keyword">unsafe</span><span> </span><span class="hs-string">&quot;HsWin32.h prim_SORTIDFROMLCID&quot;</span><span>
</span><span id="line-472"></span><span>  </span><span class="hs-identifier">sORTIDFROMLCID</span><span> </span><span class="hs-glyph">::</span><span> </span><span class="hs-identifier">LCID</span><span> </span><span class="hs-glyph">-&gt;</span><span> </span><span class="hs-identifier">SortID</span><span>
</span><span id="line-473"></span><span>
</span><span id="line-474"></span><span class="hs-keyword">type</span><span> </span><span class="hs-identifier">SubLANGID</span><span> </span><span class="hs-glyph">=</span><span> </span><span class="hs-identifier">WORD</span><span>
</span><span id="line-475"></span><span class="hs-keyword">type</span><span> </span><span class="hs-identifier">PrimaryLANGID</span><span> </span><span class="hs-glyph">=</span><span> </span><span class="hs-identifier">WORD</span><span>
</span><span id="line-476"></span><span>
</span><span id="line-477"></span><span class="hs-keyword">foreign</span><span> </span><span class="hs-keyword">import</span><span> </span><span class="hs-keyword">ccall</span><span> </span><span class="hs-keyword">unsafe</span><span> </span><span class="hs-string">&quot;HsWin32.h prim_MAKELANGID&quot;</span><span>
</span><span id="line-478"></span><span>  </span><span class="hs-identifier">mAKELANGID</span><span> </span><span class="hs-glyph">::</span><span> </span><span class="hs-identifier">PrimaryLANGID</span><span> </span><span class="hs-glyph">-&gt;</span><span> </span><span class="hs-identifier">SubLANGID</span><span> </span><span class="hs-glyph">-&gt;</span><span> </span><span class="hs-identifier">LANGID</span><span>
</span><span id="line-479"></span><span>
</span><span id="line-480"></span><span class="hs-keyword">foreign</span><span> </span><span class="hs-keyword">import</span><span> </span><span class="hs-keyword">ccall</span><span> </span><span class="hs-keyword">unsafe</span><span> </span><span class="hs-string">&quot;HsWin32.h prim_PRIMARYLANGID&quot;</span><span>
</span><span id="line-481"></span><span>  </span><span class="hs-identifier">pRIMARYLANGID</span><span> </span><span class="hs-glyph">::</span><span> </span><span class="hs-identifier">LANGID</span><span> </span><span class="hs-glyph">-&gt;</span><span> </span><span class="hs-identifier">PrimaryLANGID</span><span>
</span><span id="line-482"></span><span>
</span><span id="line-483"></span><span class="hs-keyword">foreign</span><span> </span><span class="hs-keyword">import</span><span> </span><span class="hs-keyword">ccall</span><span> </span><span class="hs-keyword">unsafe</span><span> </span><span class="hs-string">&quot;HsWin32.h prim_SUBLANGID&quot;</span><span>
</span><span id="line-484"></span><span>  </span><span class="hs-identifier">sUBLANGID</span><span> </span><span class="hs-glyph">::</span><span> </span><span class="hs-identifier">LANGID</span><span> </span><span class="hs-glyph">-&gt;</span><span> </span><span class="hs-identifier">SubLANGID</span><span>
</span><span id="line-485"></span><span>
</span><span id="line-486"></span><span class="hs-comment">----------------------------------------------------------------</span><span>
</span><span id="line-487"></span><span class="hs-comment">-- End</span><span>
</span><span id="line-488"></span><span class="hs-comment">----------------------------------------------------------------</span><span>
</span><span id="line-489"></span></pre></body></html>